How to use NextAuth useSession on Storybook 8
Mark Kop

Mark Kop @heymarkkop

About: A fullstack developer inspired by learning and sharing. (him/he)

Location:
Florianópolis, Santa Catarina, Brasil
Joined:
Aug 24, 2019

How to use NextAuth useSession on Storybook 8

Publish Date: May 14 '24
4 0

If you want to mock some NextAuth session data so a Story on Storybook 8 behaves as the user is logged in, you can use the <SessionContext> provider in the Story decorator as follows:

  decorators: [
    (Story, context) => {
      return (
        <NextAuthProvider>
          // Put your mocked session data here
          <SessionContext.Provider value={{ data: {} }}>
            <Story />
          </SessionContext.Provider>
        </NextAuthProvider>
      )
    },
  ],
Enter fullscreen mode Exit fullscreen mode

A guy made an addon once, but it's now outdated:
https://github.com/TomFreudenberg/next-auth-mock

Comments 0 total

    Add comment