Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVEREST-688 | logout on HTTP 400 JWT error #1098

Merged
merged 13 commits into from
Feb 20, 2025
Merged
Prev Previous commit
Next Next commit
chore: logout when failing to decode JWT
  • Loading branch information
fabio-silva committed Feb 13, 2025
commit 283b04201995320e51194f92bf87e1c60aa16ce0
48 changes: 26 additions & 22 deletions ui/apps/everest/src/contexts/auth/auth.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,36 @@ const AuthProvider = ({ children, isSsoEnabled }: AuthProviderProps) => {
}

const authRoutine = async (token: string) => {
const decoded = jwtDecode(token);
const iss = decoded.iss;
const exp = decoded.exp;
if (iss === EVEREST_JWT_ISSUER) {
const isTokenValid = await checkAuth(token);
const username =
decoded.sub?.substring(0, decoded.sub.indexOf(':')) || '';
if (isTokenValid) {
setLoggedInStatus(username);
try {
const decoded = jwtDecode(token);
const iss = decoded.iss;
const exp = decoded.exp;
if (iss === EVEREST_JWT_ISSUER) {
const isTokenValid = await checkAuth(token);
const username =
decoded.sub?.substring(0, decoded.sub.indexOf(':')) || '';
if (isTokenValid) {
setLoggedInStatus(username);
} else {
setLogoutStatus();
}
} else {
setLogoutStatus();
}
} else {
if (isAfter(new Date(), new Date((exp || 0) * 1000))) {
silentlyRenewToken();
return;
}
if (isAfter(new Date(), new Date((exp || 0) * 1000))) {
silentlyRenewToken();
return;
}

const user = await userManager.getUser();
const user = await userManager.getUser();

if (!user) {
setLogoutStatus();
} else {
setLoggedInStatus(decoded.sub || '');
return;
if (!user) {
setLogoutStatus();
} else {
setLoggedInStatus(decoded.sub || '');
return;
}
}
} catch (error) {
logout();
}
};
const savedToken = localStorage.getItem('everestToken');
Expand Down