admin管理员组文章数量:1355522
When the user is logged in, the code works correctly, the user authorizes the app and redirects me correctly to --> api/x/callback, the problem is when I have a user who is not logged in to X, when I access --> api/auth/x/callback, it redirects me to X's login, I log in correctly, but it does not redirect me correctly to the (Authorize App) page, but instead it redirects me to X's profile, does anyone know a solution to this problem, I would greatly appreciate your help
this is --> api/auth/x/callback
import { NextResponse } from 'next/server'
import crypto from 'crypto'
const X_CLIENT_ID = process.env.X_CLIENT_ID as string
const REDIRECT_URI = `${process.env.NEXT_PUBLIC_URL}${process.env.NEXT_PUBLIC_X_REDIRECT_URI}`
export async function GET() {
if (!X_CLIENT_ID) {
return NextResponse.json(
{ error: 'X_CLIENT_ID is not defined' },
{ status: 500 }
)
}
const codeVerifier = crypto.randomBytes(32).toString('hex')
const codeChallenge = crypto
.createHash('sha256')
.update(codeVerifier)
.digest('base64url')
const response = NextResponse.redirect(
`?${new URLSearchParams({
response_type: 'code',
client_id: X_CLIENT_ID,
redirect_uri: REDIRECT_URI,
scope: 'tweet.read tweet.write users.read offline.access',
state: crypto.randomBytes(16).toString('hex'),
code_challenge: codeChallenge,
code_challenge_method: 'S256'
})}`
)
response.cookies.set('code_twitter_verifier', codeVerifier, {
httpOnly: true,
secure: true,
sameSite: 'lax',
path: '/'
})
return response
}
本文标签: javascriptHow can I redirect correctly after logging into TwitterStack Overflow
版权声明:本文标题:javascript - How can I redirect correctly after logging into Twitter? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743995585a2572928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论