下一个身份验证登录不适用于 Next.Js 13

问题描述 投票:0回答:1

我最近创建了一个 Next.Js (13.4.19) 应用程序,并使用 next-auth (4.23.1) 来管理身份验证系统。我已按照本教程(https://www.youtube.com/watch?v=w2h54xz6Ndw&t=2054s)进行操作,并仅使用提供程序(GitHub 和 Google)完成了设置我的身份验证系统的所有操作。

当我尝试登录时出现问题:应用程序将我发送到正确的登录路径(api/auth/signin),当我单击按钮时没有任何反应;页面自行刷新,但控制台中没有错误。

这是我的代码:

app/api/auth/[...nextauth]/route.ts

import NextAuth from 'next-auth/next';
import { options } from '@/app/utils/options';

const handler = NextAuth(options);

export { handler as GET, handler as POST };

app/utils/options.ts

import type { NextAuthOptions } from 'next-auth';
import { validateCredentials } from './helpers/getCredentials';

import GoogleProvider from 'next-auth/providers/google';
import GithubProvider from 'next-auth/providers/github';
import DiscordProvider from 'next-auth/providers/discord';

const googleCredentials = validateCredentials(
  process.env.GOOGLE_CLIENT_ID!,
  process.env.GOOGLE_CLIENT_SECRET!
);

const githubCredentials = validateCredentials(
  process.env.GITHUB_CLIENT_ID!,
  process.env.GITHUB_CLIENT_SECRET!
);

export const options: NextAuthOptions = {
  providers: [
    GoogleProvider({
      clientId: googleCredentials.clientId,
      clientSecret: googleCredentials.clientSecret,
    }),
    GithubProvider({
      clientId: githubCredentials.clientId,
      clientSecret: githubCredentials.clientSecret,
    }),
  ],
};

以下是我创建的 GitHub OAuth 应用程序的设置

我尝试在 youtube 和 github 上观看其他可能的解决方案,但没有任何效果。每次我尝试登录时都没有任何反应。例如,如果我点击 GitHub 按钮,它应该将我重定向到 github 登录页面;相反,当前页面刷新并且没有任何反应。

next.js oauth google-oauth next-auth
1个回答
0
投票

我也面临着同样的问题。有趣的是,当我重新访问以前的项目时,它曾经工作过,我也遇到了同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.