diff --git a/backend/src/misc/jwt.ts b/backend/src/misc/jwt.ts index 395b158b..24d52d79 100644 --- a/backend/src/misc/jwt.ts +++ b/backend/src/misc/jwt.ts @@ -17,7 +17,9 @@ const issuers: Record = { }; 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) { @@ -50,7 +52,10 @@ export async function verifyKeycloakToken(tokenStr: string): Promise { export async function checkToken( tokenStr: string, ): Promise { - const tokenDecoded = jwt.decode(tokenStr) as TokenPayload; + const tokenDecoded = jwt.decode(tokenStr) as TokenPayload | null; + if (!tokenDecoded) { + return null; + } const issuer = tokenIssuerToName(tokenDecoded.iss || "");