auth0 / auth0-react

Auth0 SDK for React Single Page Applications (SPA)
MIT License
887 stars 256 forks source link

Add warning when calling `useAuth0` outside of `Auth0Provider` #697

Closed beaverusiv closed 10 months ago

beaverusiv commented 10 months ago

Checklist

Describe the problem you'd like to have solved

When a component that calls useAuth0 does so without being wrapped in an Auth0Provider it silently sits at loading: true forever.

Describe the ideal solution

Usually when working with a context I will create logic like so:

export const useApplicant = () => {
    const context = useContext(ApplicantContext);

    if (context === undefined) {
        throw new Error('useApplicant must be used within a ApplicantProvider');
    }

    return context;
};

I believe similar logic can be implemented to check for this scenario

Alternatives and current workarounds

No response

Additional context

No response

frederikprijck commented 10 months ago

Thanks, we currently have no plans to add this as that would, technically, we a breaking change.

There is react-redux that does this only when not in PRODUCTION mode, but that would still be a breaking change. While others, such as react-router, do not do this at all.

Even though I understand the decreased experience, given the fact that it's a breaking change, this isn't something we can accomodate for for the time being.