我正在使用 ExpressJS 和 Supabase Auth 创建“使用 Google 登录”按钮。因此,用户单击按钮后,它将被重定向到路由“/login/google”,并且将被重定向到 Google 帐户表单以选择用户喜欢的帐户,然后重定向回“/login/” google/callback”,我需要从 url 获取 access_token 和 refresh_token 到 setSession。
问题是返回 URL 包含“#”而不是“?”,因此我不可能从服务器端获取参数。
返回的 URL 示例:
http://localhost:3000/login/google/callback#access_token=XXX&expires_at=XXX&expires_in=XXX&provider_token=XXX&refresh_token=XXX&token_type=bearer
Google 的“选择帐户”中显示的 URL:
https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?client_id=XXX&redirect_to=http%3A%2F%2Flocalhost%3A3000%2Flogin%2Fgoogle%2Fcallback&redirect_uri=<SUPABASE_URL_WITH_PROJECT_ID>&response_type=code&scope=email%20profile&state=XXX&service=lso&o2v=2&theme=glif&flowName=GeneralOAuthFlow
我的代码:
app.get('/login/google', async (req, res) => {
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'http://localhost:3000/login/google/callback',
scope: ' profile email',
},
});
res.redirect(data.url);
});
我已经检查了很多关于我遇到的问题的帖子,但解决方案是将response_type更改为代码而不是令牌,但我的已经是代码了。
嘿,你明白了吗?有同样的问题