Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-queens-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navigraph/auth": patch
---

Improved handling of signouts on failed initialization or token refresh attempts.
5 changes: 4 additions & 1 deletion packages/auth/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
7 changes: 4 additions & 3 deletions packages/auth/src/network.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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;
Expand Down