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

fix: tokens not cleared in DB when session times out #115

Merged
merged 1 commit into from
Jul 18, 2024
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
10 changes: 10 additions & 0 deletions packages/auth-provider/src/common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AUTH_TYPES,
HEADERS,
JWT,
decodeToken,
verifyAndExtractToken,
} from "@versini/auth-common";
import { getFingerprintHash } from "@versini/ui-fingerprint";
Expand All @@ -13,6 +14,15 @@ import type { ServiceCallProps } from "./types";
const isProd = process.env.NODE_ENV === "production";
const isDev = !isProd;

export const getUserIdFromToken = (token: string) => {
try {
const jwt = decodeToken(token);
return jwt ? (jwt[JWT.USER_ID_KEY] as string) : "";
} catch (_error) {
return "";
}
};

export const serviceCall = async ({
type,
clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
authenticateUser,
getCustomFingerprint,
getPreAuthCode,
getUserIdFromToken,
graphQLCall,
logoutUser,
} from "../../common/utilities";
Expand Down Expand Up @@ -106,8 +107,14 @@ export const AuthProvider = ({
async (message: string) => {
logger("invalidateAndLogout: invalidating and logging out");
const { user } = state;
const userId = user?.userId || getUserIdFromToken(idToken);
if (!userId) {
logger(
"invalidateAndLogout: user cannot be identified, logging out without userId",
);
}
await logoutUser({
userId: user?.userId || "",
userId,
idToken,
accessToken,
refreshToken,
Expand Down