Expose SessionContext to create SessionProvider for Testing and StoryBook #5437
TomFreudenberg
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Created PR #5438 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using storybook and jest testing.
I want to provide dynamically usage of session data when working on stories. Using globalTypes with parameter for user session does not allow to change the preview inside storybook without reload in case that the next-auth
SessionProvider
just use thesession
property as an `hasInitialSession' flag.I have patched the current next-auth release and just exported the SessionContext from next-auth/react:
https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/react/index.tsx#L77-L79
just with the
export
statement into:Having the
SessionContext
exported allows to (re)write a simpleSessionProvider
like:This will allow to define some fixed user and session data for testing and mocking.
The example will show just a blank page on 'loading' and different messages for 'unauthenticated' and 'authenticated' user data.
Would you like to accept a PR to just export the
SessionContext
or do you have some better options?I want to prevent using libraries like
rewire
orstub
.Beta Was this translation helpful? Give feedback.
All reactions