DEV Community

Cover image for How to use NextAuth useSession on Storybook 8
Mark Kop
Mark Kop

Posted on

4

How to use NextAuth useSession on Storybook 8

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

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️