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

loaded profile cannot be obtained from session hook, and skipping the loading breaks the SessionContext logout updates #970

Open
pduchesne opened this issue May 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@pduchesne
Copy link

Search terms you've used

profile, logout

Bug description

There is a problem with the way the profiles are used in the session init.
The problem is two-fold :

  • profiles are loaded by default on session init, and set in a state that is part of the SessionContext. However these profiles are not exposed by the useSession hook, making them useless, and therefore wasting an HTTP request on login :
    export default function useSession(): SessionInfo {
    const { session, sessionRequestInProgress, fetch, login, logout } =
    useContext(SessionContext);
    return {
    session,
    sessionRequestInProgress,
    fetch,
    login,
    logout,
    };
  • the skipLoadingProfiles flag can be used to remove that behaviour. However, it turns out the profile state is the only variable that triggers a session context update when logging out (the session object does not get updated by a logout, only its internal isLoggedIn field)
    return (
    <SessionContext.Provider
    value={{
    session,
    login: contextLogin,
    logout: contextLogout,
    sessionRequestInProgress,
    setSessionRequestInProgress,
    fetch,
    profile,
    }}

So trying to disable the profile loading actually disables the logout updates one can expect from a SessionProvider, thereby mandating the explicit use of an onLogout callback.

Expected result

  • have the profile exposed through the useSession hook
  • be able to use skipLoadingProfiles while relying SessionProvider to trigger proper updates on logout

Additional information

Tested with 3.0.0

@pduchesne pduchesne added the bug Something isn't working label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant