Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stateful session cookie expiry on set #1115

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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