diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx index 4c196051f40c..0a6ad05c218f 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx @@ -31,7 +31,9 @@ const MESSAGES = { forgotPasswordSuccess: 'We have sent you an email with further instructions!', changePasswordSuccess: 'Successfully changed password!', resetPasswordSuccess: 'Successfully reset password!', + signOutLoading: 'Logging out...', signOutSuccess: 'Successfully logged out!', + signOutError: 'Error logging out, please try again.', pleaseWait: 'Please wait...', } as const @@ -149,7 +151,7 @@ export interface AuthProviderProps { export function AuthProvider(props: AuthProviderProps) { const { authService, onAuthenticated, children } = props const { cognito } = authService - const { session } = sessionProvider.useSession() + const { session, deinitializeSession } = sessionProvider.useSession() const { setBackend } = backendProvider.useSetBackend() const logger = loggerProvider.useLogger() const navigate = router.useNavigate() @@ -326,9 +328,14 @@ export function AuthProvider(props: AuthProviderProps) { } const signOut = async () => { + deinitializeSession() setInitialized(false) - await cognito.signOut() - toast.success(MESSAGES.signOutSuccess) + setUserSession(null) + await toast.promise(cognito.signOut(), { + success: MESSAGES.signOutSuccess, + error: MESSAGES.signOutError, + loading: MESSAGES.signOutLoading, + }) return true } diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/session.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/session.tsx index 4fc45e826080..5639e3f1110b 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/session.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/session.tsx @@ -16,6 +16,8 @@ import * as listen from '../listen' /** State contained in a {@link SessionContext}. */ interface SessionContextType { session: results.Option + /** Set `initialized` to false. Must be called when logging out. */ + deinitializeSession: () => void } /** See `AuthContext` for safety details. */ @@ -58,7 +60,7 @@ export function SessionProvider(props: SessionProviderProps) { const [initialized, setInitialized] = react.useState(false) /** Register an async effect that will fetch the user's session whenever the `refresh` state is - * incremented. This is useful when a user has just logged in (as their cached credentials are + * set. This is useful when a user has just logged in (as their cached credentials are * out of date, so this will update them). */ const session = hooks.useAsyncEffect( results.None, @@ -112,10 +114,14 @@ export function SessionProvider(props: SessionProviderProps) { return cancel }, [registerAuthEventListener]) - const value = { session } + const deinitializeSession = () => { + setInitialized(false) + } return ( - {initialized && children} + + {initialized && children} + ) }