Skip to content

Commit

Permalink
Fix error if no issuer found in token
Browse files Browse the repository at this point in the history
  • Loading branch information
gf-rog committed Mar 22, 2024
1 parent fe4adde commit eecea12
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/src/misc/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const issuers: Record<Issuer, string> = {
};

export function generateAccessToken(userId: string) {
return jwt.sign({ iss: issuers["rest"], userId }, process.env.TOKEN_SECRET!, { expiresIn: 900 });
return jwt.sign({ iss: issuers["rest"], userId }, process.env.TOKEN_SECRET!, {
expiresIn: 900,
});
}

export function generateRefreshToken(userId: string) {
Expand Down Expand Up @@ -50,7 +52,10 @@ export async function verifyKeycloakToken(tokenStr: string): Promise<boolean> {
export async function checkToken(
tokenStr: string,
): Promise<TokenPayload | null> {
const tokenDecoded = jwt.decode(tokenStr) as TokenPayload;
const tokenDecoded = jwt.decode(tokenStr) as TokenPayload | null;
if (!tokenDecoded) {
return null;
}

const issuer = tokenIssuerToName(tokenDecoded.iss || "");

Expand Down

0 comments on commit eecea12

Please sign in to comment.