2

I am using Next.js in combination with next-auth and next-i18next.

I use useSession() (with the next-auth/client Provider in my _app.js) to check if the user is authenticated. Once authenticated, navigation is very quick and the current session is kept between page renders. Until I switch the locale. After switching, the loading state (coming from useSession()) switches to true.

The loading state stays true, until I focus to another browser tab and come back.

I would hope the session would also be kept between locales, just like it is kept between page navigations...

I have no idea why this is happening, and if this behavior is normal.

To switch locales I use:

<Link href={router.asPath} locale="en">EN</Link>
Thom
  • 21
  • 2

1 Answers1

0

I had the same issue, try to add getSession to getServerSideProps. it worked for me.

    import { getSession } from 'next-auth/react'

    export async function getServerSideProps(context) {
      const session = await getSession(context)
      const authorized = !!session?.jwt
      return {
        props: { authorized },
      }
    }
Adel Hamad
  • 23
  • 1
  • 5