diff --git a/.changeset/soft-queens-warn.md b/.changeset/soft-queens-warn.md new file mode 100644 index 0000000..34ff37e --- /dev/null +++ b/.changeset/soft-queens-warn.md @@ -0,0 +1,5 @@ +--- +"@navigraph/auth": patch +--- + +Improved handling of signouts on failed initialization or token refresh attempts. diff --git a/packages/auth/src/api.ts b/packages/auth/src/api.ts index 04c2efb..ec845f3 100644 --- a/packages/auth/src/api.ts +++ b/packages/auth/src/api.ts @@ -85,6 +85,9 @@ export const getAuth = ({ keys, storage }: AuthParameters = {}): NavigraphAuth = const loadPersistedCredentials = async () => { if (INITIALIZED) return Promise.resolve(); - await verifyUser().catch(() => Logger.warning("Failed to load persisted credentials")); + await verifyUser().catch((e) => { + Logger.warning("Failed to load persisted credentials", e); + signOut().catch((e) => Logger.warning("Failed to sign out after failed initialization attempt", e)); + }); setInitialized(true); }; diff --git a/packages/auth/src/network.ts b/packages/auth/src/network.ts index 74df794..d8e6666 100644 --- a/packages/auth/src/network.ts +++ b/packages/auth/src/network.ts @@ -1,7 +1,8 @@ -import { getApp } from "@navigraph/app"; +import { Logger, getApp } from "@navigraph/app"; import axios from "axios"; import { tokenCall } from "./flows/shared"; -import { LISTENERS, tokenStorage } from "./internal"; +import { tokenStorage } from "./internal"; +import { signOut } from "./internal"; export const navigraphRequest = axios.create(); @@ -45,7 +46,7 @@ navigraphRequest.interceptors.response.use( } // If refresh attempt fails, logout - LISTENERS.forEach((listener) => listener(null)); + signOut().catch((e) => Logger.warning("Failed to sign out after a token refresh failure", e)); } throw error;