Skip to content

Commit 33f1bdd

Browse files
authored
Invalidate sessions on auth error + bump version (#1198)
1 parent 00b9159 commit 33f1bdd

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "surrealist",
33
"private": true,
4-
"version": "3.8.3",
4+
"version": "3.8.4",
55
"surreal": "2.0.0",
66
"type": "module",
77
"authors": [

src/components/App/hooks/cloud.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ function handleAuthFailure(failure: AuthFailure, signIn: () => Promise<void>) {
4848
* Automatically set up the cloud authentication flow
4949
*/
5050
export 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

Comments
 (0)