Skip to content

Commit

Permalink
Update stateful session cookie expiry on set (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Mar 17, 2023
2 parents d30d77f + 6e77701 commit 12e979c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/auth0-session/session/stateful-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export class StatefulSession<
if (!sessionId) {
sessionId = await genId!(req);
debug('generated new session id %o', sessionId);
const cookieValue = await generateCookieValue(sessionName, sessionId, keys[0]);
cookieSetter.set(sessionName, cookieValue, cookieOptions);
cookieSetter.commit(res);
}
debug('set session %o', sessionId);
const cookieValue = await generateCookieValue(sessionName, sessionId, keys[0]);
cookieSetter.set(sessionName, cookieValue, cookieOptions);
cookieSetter.commit(res);
await this.store.set(sessionId, {
header: { iat, uat, exp },
data: session
Expand Down
11 changes: 11 additions & 0 deletions tests/auth0-session/session/stateful-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ describe('StatefulSession', () => {
});

it('should get an existing session', async () => {
await store.set('foo', await getPayload());
const baseURL = await setup(config);
const cookieJar = await toSignedCookieJar({ appSession: 'foo' }, baseURL);
const [cookie] = await cookieJar.getCookies(baseURL);
const expires = cookie.expires;
await get(baseURL, '/session', { cookieJar });
const [updatedCookie] = await cookieJar.getCookies(baseURL);
expect(updatedCookie.expires > expires);
});

it('should update the cookie expiry when setting an existing session', async () => {
await store.set('foo', await getPayload());
const baseURL = await setup(config);
const cookieJar = await toSignedCookieJar({ appSession: 'foo' }, baseURL);
Expand Down

0 comments on commit 12e979c

Please sign in to comment.