Supabase与Next.js 13应用程序路由OAuth未登录。

huangapple go评论66阅读模式
英文:

Supabase with Next.js 13 App Router OAuth not logging in

问题

每当我使用以下代码登录:

  // twitch signin handler
  const handleTwitchSignIn = async () => {
    const { data, error } = await supabase.auth.signInWithOAuth({
      provider: "twitch",
      options: {
        redirectTo: `${location.origin}/${lang}/auth/callback`,
      },
    });
  };

  // google signin handler
  const handleGoogleSignIn = async () => {
    const { data, error } = await supabase.auth.signInWithOAuth({
      provider: "google",
      options: {
        redirectTo: `${location.origin}/${lang}/auth/callback`,
      },
    });
  };

我没有收到任何应该重定向到/auth/callback的“code”参数。

文档中似乎没有提及这一点。我看到cookie值是code-verifier,但url中缺少code本身。

英文:

Whenever I log in with

  // twitch signin handler
  const handleTwitchSignIn = async () => {
    const { data, error } = await supabase.auth.signInWithOAuth({
      provider: "twitch",
      options: {
        redirectTo: `${location.origin}/${lang}/auth/callback`,
      },
    });
  };

  // google signin handler
  const handleGoogleSignIn = async () => {
    const { data, error } = await supabase.auth.signInWithOAuth({
      provider: "google",
      options: {
        redirectTo: `${location.origin}/${lang}/auth/callback`,
      },
    });
  };

I don't get any "code" param back that is supposed to be redirected into /auth/callback.

None of the doc seems to talk about this. I see the cookie value being the code-verifier, but the code itself is missing from the url.

答案1

得分: 2

在阅读了许多关于PKCE以及查看了auth-helper-nextjs库的代码后,我花了好几个小时,但找不到正确的答案。

原来,你只需在Supabase控制台中添加一个重定向URL策略。
此外,你可以看到我的URL具有语言动态URL,因为启用了i18n。

Supabase与Next.js 13应用程序路由OAuth未登录。

英文:

I spent hours reading PKCE and going through the auth-helper-nextjs library code but couldn't find the correct answer.

It turns out, you simply have to add a Redirect URL policy in Supabase console.
Also, you can see mine has language dynamic url due to i18n enabled.

Supabase与Next.js 13应用程序路由OAuth未登录。

huangapple
  • 本文由 发表于 2023年7月6日 20:01:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定