@@ -48,8 +48,14 @@ function handleAuthFailure(failure: AuthFailure, signIn: () => Promise<void>) {
4848 * Automatically set up the cloud authentication flow
4949 */
5050export function useCloudAuthentication ( ) {
51- const { isAuthenticated, isLoading, getAccessTokenSilently, handleRedirectCallback, error } =
52- useAuth0 ( ) ;
51+ const {
52+ isAuthenticated,
53+ logout,
54+ isLoading,
55+ getAccessTokenSilently,
56+ handleRedirectCallback,
57+ error,
58+ } = useAuth0 ( ) ;
5359
5460 const { signIn } = useAuthentication ( ) ;
5561 const hasInitialised = useRef ( false ) ;
@@ -96,11 +102,19 @@ export function useCloudAuthentication() {
96102 const accessToken = await getAccessTokenSilently ( ) ;
97103 await acquireSession ( accessToken , false ) ;
98104 } catch ( err : any ) {
99- console . error ( "Failed to acquire cloud session on init" , err ) ;
105+ adapter . warn (
106+ "Auth" ,
107+ `Failed to acquire cloud session on init: ${ err ?. message ?? err } ` ,
108+ ) ;
109+
110+ useCloudStore . getState ( ) . setSessionExpired ( true ) ;
111+
112+ invalidateSession ( ) ;
113+ await logout ( { openUrl : false } ) ;
100114 }
101115 } ) ( ) ;
102116 }
103- } , [ isAuthenticated , isLoading , getAccessTokenSilently ] ) ;
117+ } , [ isAuthenticated , isLoading , logout , getAccessTokenSilently ] ) ;
104118
105119 // Handle Auth0 authentication errors
106120 useEffect ( ( ) => {
0 commit comments