Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export context for stubbing default Provider behaviour #324

Closed
wants to merge 1 commit into from

Conversation

adamjmcgrath
Copy link
Contributor

Description

Export UserContext so that you can create your own UserContext.Provider - this is useful if you want to override the default Auth0Provider behaviour, in testing particularly.

Eg to disable the profile request on page load and only derive the user from any server side code, you can do:

import React from 'react';
import type { AppProps } from 'next/app';
import { UserProvider } from '@auth0/nextjs-auth0';
import { UserContext } from '@auth0/nextjs-auth0';

export default function App({ Component, pageProps }: AppProps): React.ReactElement<AppProps> {
  const { user } = pageProps;

  return (
    <UserContext.Provider value={{ user, isLoading: false, checkSession: () => Promise.resolve() }}>
      <Component {...pageProps} />
    </UserContext.Provider>
  );
}

(you'd only need to stub checkSession to keep TS happy)

References

fixes #313

@adamjmcgrath adamjmcgrath added the review:small Small review label Mar 4, 2021
@adamjmcgrath adamjmcgrath requested a review from a team as a code owner March 4, 2021 12:01
@vercel
Copy link

vercel bot commented Mar 4, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/auth0/nextjs-auth0/FVbrkUuQupfzHmW5eWwgmUcehfyE
✅ Preview: Canceled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:small Small review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to disable fetching in UserProvider
1 participant