【问题标题】:Nextauth TypeError: Cannot read property 'useState' of null when using SessionProviderNextauth TypeError:使用 SessionProvider 时无法读取 null 的属性“useState”
【发布时间】:2022-06-15 03:22:58
【问题描述】:

当我尝试将 SessionProvider 添加到我的 NextJS 应用程序时,我得到 TypeError: Cannot read property 'useState' of null 错误。 我不明白我应该做什么? 我可以毫无问题地使用 Google 登录。只有当我在 SessionProvider 提供程序中添加时,我才收到此错误。

// _app.tsx

import '../styles/globals.css'
import type { AppProps } from 'next/app'
import { SessionProvider } from 'next-auth/react'

function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
  return (
    <SessionProvider session={session}>
      <Component {...pageProps} />
    </SessionProvider>
  )
}

// [...nextauth.js]

import NextAuth from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_SECRET,
    }),
  ],
  pages: {
      signIn: "/auth/signin",

  }
})

我还注意到我的会话在注销时是一个空对象。 谢谢!

【问题讨论】:

    标签: reactjs authentication next.js next-auth


    【解决方案1】:

    我以前也遇到过。您可以尝试将 "next-auth": "^4.0.1" 放入 package.json 中的“依赖项”。

    【讨论】:

      猜你喜欢
      • 2023-02-08
      • 2022-06-18
      • 2020-01-29
      • 2022-01-12
      • 2021-12-04
      • 2021-12-17
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多