fix(core): Fix browser session refreshes not working (#9212)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Danny Martini 2024-04-24 18:28:19 +02:00 committed by GitHub
parent 306b68da6b
commit 1efeeccc5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -150,7 +150,7 @@ export class AuthService {
if (jwtPayload.exp * 1000 - Date.now() < this.jwtRefreshTimeout) {
this.logger.debug('JWT about to expire. Will be refreshed');
this.issueCookie(res, user, jwtPayload.browserId);
this.issueCookie(res, user, req.browserId);
}
return user;

View file

@ -202,6 +202,13 @@ describe('AuthService', () => {
sameSite: 'lax',
secure: false,
});
const newToken = res.cookie.mock.calls[0].at(1);
expect(newToken).not.toBe(validToken);
expect(await authService.resolveJwt(newToken, req, res)).toEqual(user);
expect((jwt.decode(newToken) as jwt.JwtPayload).browserId).toEqual(
(jwt.decode(validToken) as jwt.JwtPayload).browserId,
);
});
it('should refresh the cookie only if less than 1/4th of time is left', async () => {