Skip to content

Commit

Permalink
fix(core): Fix browser session refreshes not working (#9212)
Browse files Browse the repository at this point in the history
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <[email protected]>
  • Loading branch information
2 people authored and ivov committed Apr 25, 2024
1 parent 9bd8492 commit a67246c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/cli/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/test/unit/auth/auth.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit a67246c

Please sign in to comment.