首页 > 解决方案 > 我使用谷歌登录在我的 NextJs 应用程序中得到 http://localhost:3000/api/auth/error。为什么?

问题描述

这是我的 [...nextauth].js 文件...

import NextAuth from "next-auth";
import Providers from "next-auth/providers";

export default NextAuth({
  providers: [
    Providers.Google({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET,
    }),
  ],
});

这是我要传递登录功能的标题组件...

import { signIn, signOut, useSession } from "next-auth/client";

function Header() {
    return(
     <div onClick={signIn}>
          <p>Sign In</p>
     </div>
    )

当我点击它时,它会返回一个 404 响应,但我应该在下面看到:

用google next js界面登录

我错过了什么?

标签: reactjsnext-auth

解决方案


I got the blunder. It was in my file naming. It is supposed to be pages/api/auth not pages/api/Auth. Fix that and it will work. This is for anyone else who will find themselves in this small bug.


推荐阅读