Skip to content

Commit

Permalink
Fix QCreate failing after token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
fjallnari committed Sep 21, 2024
1 parent 613db84 commit c0d866c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { cssVarTheme } from "./util/util";
import { THEMES } from "./enum/Themes";
const maxAge = 10000; // for memoizing refresh token
const maxAge = 60; // for memoizing refresh token
$: memoizedRefreshToken();
Expand Down Expand Up @@ -60,8 +60,8 @@
accessToken.set(response.data.accessToken);
setTimeout(() => {
memoizedRefreshToken();
}, 600000 - 500);
memoizedRefreshToken();
}, 600000 - 30000); // 10 minutes - 30 seconds
if (response.status === 200 && $location === '/auth') {
replace('/');
Expand Down
2 changes: 2 additions & 0 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextFunction, Request, Response } from "express";
import jwt from "jsonwebtoken";
import { ObjectId } from "mongodb";
import logger from "../logger";

declare global {
namespace Express {
Expand All @@ -26,6 +27,7 @@ const verifyToken = (req: Request, res: Response, next: NextFunction) => {

req.user = Object.assign(jwtObj?.user, { _id: new ObjectId(jwtObj?.user._id)});
} catch (err) {
logger.error({ error: err }, `JWT token is invalid`);
return res.status(401).send("Invalid token");
}
return next();
Expand Down

0 comments on commit c0d866c

Please sign in to comment.