Skip to content

Add Mocks for Storybook #1755

Closed
Closed
@mscottford

Description

@mscottford

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
    I have looked into the API documentation and have not found a suitable solution or answer.
    I have searched the issues and have not found a suitable solution or answer.
    I have searched the Auth0 Community forums and have not found a suitable solution or answer.
    I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

After the Storybook 8.1 release announcement, I was intrigued by the idea of write Storybook stories for my page components that are written with the Next.js App Router. So I started digging into the example repository that's mentioned in the blog post, and I've been digging into the code that powers the Next.js mocks that Storybook has published.

The page component that I'm attempting to write story for is wrapped with a call withPageAuthRequired function, and I don't see any published resources for how to use or craft mocks for this library.

Describe the ideal solution

I'd ideally like to see official mocks published with this package or published in a sibling package.

Alternatives and current workarounds

I've attempted to dig into the session handling logic to see if there's a way that I can simulate a valid session by mocking the cookie access, since there is already a published mock for doing so (see example usage). However, it looks like I would need to duplicate the logic that is used to encrypt the contents of the cookie. I would rather just be able to mock whether or not someone is logged in along with the profile information that would be provided by useUser.

Additional context

There is an additional blog post that Storybook has published which outlines the module mocking approach that they are following. All of the mocks that Storybook ships for Next can be found in that project's export-mocks folder. I suspect that it's going to be a good resource to learn from.

Activity

arpit-jn

arpit-jn commented on May 27, 2025

@arpit-jn
Contributor

Hello, could you please give generatesessioncookie helper function a try and let us know if this works for you? Though the example shared is for v4, it should work for v3 as well.

I hope this addresses your concerns. Please feel free to reach out if you still face this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mscottford@tusharpandey13@arpit-jn

        Issue actions

          Add Mocks for Storybook · Issue #1755 · auth0/nextjs-auth0