Skip to content

Commit

Permalink
feat: Logout user when Access token has expired (#2137)
Browse files Browse the repository at this point in the history
  • Loading branch information
NigelBreslaw authored Jul 24, 2024
1 parent 3c481c9 commit 96aae68
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions native/app/store/Authentication/AuthenticationLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export async function loadToken(membershipId: string): Promise<AuthToken | null>

async function getUpdatedAccessToken(token: AuthToken): Promise<AuthToken> {
const isValidRefresh = isValidRefreshToken(token);

if (!isValidRefresh) {
// Nothing can be done. The user needs to re-auth.
// TODO: Log out the user
console.error("Refresh token expired");
throw new Error("Refresh token expired");
}
Expand Down Expand Up @@ -122,12 +122,17 @@ async function getTokenInternal(
errorMessage: string,
): Promise<AuthToken> {
try {
console.log("getTokenInternal!!!");
const updatedToken = await getUpdatedAccessToken(authToken);
return updatedToken;
} catch (e) {
console.error("Failed to validate token", errorMessage, e);
const error = e as Error;
if (error.message === "ProvidedTokenNotValidRefreshToken" || error.message.includes("NotFound (SQL Return Value")) {
if (
error.message === "ProvidedTokenNotValidRefreshToken" ||
error.message.includes("NotFound (SQL Return Value") ||
error.message.includes("Refresh token expired")
) {
console.error(error.message);
get().logoutCurrentUser();
}
Expand Down

0 comments on commit 96aae68

Please sign in to comment.