Skip to content

Storybook v8 + Next.js 14 + Auth.js setup help #26931

Answered by woodsboe
desiboli asked this question in Help
Discussion options

You must be logged in to vote

Hi @desiboli,
This may not be the perfect solution, but more of a workaround.

Create a decorator file (ex. authDecorator.tsx) and load this in your preview.ts file.

The file should contain the following:

import {SessionContext} from 'next-auth/react';

export const NextAuthDecorator = (Story) => {
  const mockSessionData = {
    expires: '',
    user: {
      name: 'Storybook',
      email: 'storybook@stories.org',
    },
  };

  return (
    <SessionContext.Provider
      value={{
        update: () => {
          return Promise.resolve(mockSessionData);
        },
        data: mockSessionData,
        status: 'authenticated',
      }}
    >
      <Story/>
    </SessionContext.Provider>…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@desiboli
Comment options

Answer selected by desiboli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants