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

SDK-3807 Add custom session stores #993

Merged
merged 12 commits into from
Jan 10, 2023
Merged

SDK-3807 Add custom session stores #993

merged 12 commits into from
Jan 10, 2023

Conversation

adamjmcgrath
Copy link
Contributor

@adamjmcgrath adamjmcgrath commented Jan 9, 2023

Adding the ability to provide a key value store like Redis to back sessions and make them stateful.

import { SessionStore, SessionStorePayload, initAuth0 } from '@auth0/nextjs-auth0';

class Store implements SessionStore {
  private store: KeyValueStoreLikeRedis<SessionStorePayload>;
  constructor() {
    // If you set the expiry accross the whole store use the session config,
    // e.g. `min(config.session.rollingDuration, config.session.absoluteDuration)`
    // the default is 24hrs
    this.store = new KeyValueStoreLikeRedis();
  }
  async get(id) {
    const val = await this.store.get(id);
    return val;
  }
  async set(id, val) {
    // To set the expiry per item, use `val.header.exp` (in secs)
    const expiryMs = val.header.exp * 1000;
    await this.store.set(id, val);
  }
  async delete(id) {
    await this.store.delete(id);
  }
}

export default initAuth0({
  session: {
    store: new Store()
  }
});

4e57b7e - Move the existing stateless cookie store
7a7e5d9 - Add stateful session store (main commit)
6468115, c5b87d8, 3e97155, efc5182 - Other commits are merges and adding/reverting deployment for the beta

fixes #279

Testing

Example app using a Redis session https://nextjs-auth0-redis-session.vercel.app/ (source code https://github.com/adamjmcgrath/nextjs-auth0-redis-session)

@adamjmcgrath adamjmcgrath added the review:large Large review label Jan 9, 2023
@adamjmcgrath adamjmcgrath requested a review from a team as a code owner January 9, 2023 12:29
@vercel
Copy link

vercel bot commented Jan 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nextjs-auth0 ⬜️ Ignored (Inspect) Jan 10, 2023 at 4:06PM (UTC)

EXAMPLES.md Outdated Show resolved Hide resolved
EXAMPLES.md Outdated Show resolved Hide resolved
EXAMPLES.md Outdated Show resolved Hide resolved
EXAMPLES.md Outdated Show resolved Hide resolved
EXAMPLES.md Show resolved Hide resolved
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
@adamjmcgrath adamjmcgrath requested a review from Widcket January 10, 2023 10:17
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
adamjmcgrath and others added 2 commits January 10, 2023 15:43
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
src/config.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Widcket Widcket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for being patient with the review.

@adamjmcgrath
Copy link
Contributor Author

Thanks for the review @Widcket!

@adamjmcgrath adamjmcgrath merged commit 79142d6 into main Jan 10, 2023
@adamjmcgrath adamjmcgrath deleted the session-stores branch January 10, 2023 16:41
@adamjmcgrath adamjmcgrath mentioned this pull request Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:large Large review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom store implementation
2 participants