mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 05:51:55 +08:00
feat: Improve OAuth state parsing and error handling in sign-in route
This commit is contained in:
parent
3b6117dc61
commit
d39cb2e7d5
@ -14,9 +14,18 @@ export async function POST(_req: Request) {
|
||||
|
||||
// 检查是否存在 OAuth 状态
|
||||
const oauthState = cookies().get("oauth_state");
|
||||
const return_url = oauthState
|
||||
? `${hostUrl}/authorize` // 如果存在 OAuth 状态,重定向到 authorize 页面
|
||||
: `${hostUrl}/dashboard`; // 否则重定向到仪表板
|
||||
let return_url = `${hostUrl}/dashboard`; // 默认重定向到仪表板
|
||||
|
||||
if (oauthState) {
|
||||
try {
|
||||
// 解码并重建 OAuth URL
|
||||
const params = JSON.parse(atob(oauthState.value));
|
||||
const searchParams = new URLSearchParams(params);
|
||||
return_url = `${hostUrl}/oauth/authorize?${searchParams.toString()}`;
|
||||
} catch (error) {
|
||||
console.error("Failed to process OAuth state:", error);
|
||||
}
|
||||
}
|
||||
|
||||
const sso = btoa(`nonce=${nonce}&return_sso_url=${return_url}`);
|
||||
const sig = hmacSHA256(sso, clientSecret).toString(Hex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user