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

feat: add server side session storage #265

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

patrick-hofmann
Copy link

This PR adds a server side storage option for sessions using useStorage.

The default behavior after this PR is still the same as before (using cookie as storageType which is the default)

export default defineNuxtConfig({
  modules: ['nuxt-auth-utils'],
  auth: {
    storageType: 'cookie', // 'memory', 'cache', 'nuxt-session'
  }
})

but now the storageType can be memory, cache or nuxt-session as well, where nuxt-session is a nitro storage mount point that can be defined in the nuxt.config.ts.

The 'non-cookie' storageTypes allow two more configs:

  auth: {
    sessionInactivityMaxAge: 60 * 60 * 24 * 30, // Session timeout after inactivity (30 days)
    autoExtendSession: true // Extend session on each request
  },

The sessionInactivityMaxAge is used to determine orphaned sessions that can be deleted with cleanupOrphanedUserSessions, which can run in a scheduled nitro task (unfortunately not on the edge) or in a server middleware or a specific route.

The session data is not encrypted to the server which can be discussed as the stored data is obvious at least in transfer to the server side anyway.

What this PR can not do, is determining multiple sessions of one user as this would need a server side user id, independent from the auth provider used (since one user could have multiple different providers).

This was referenced Oct 30, 2024
README.md Outdated
if (session && Object.keys(session).length > 0) {
await setUserSession(event, session)
}
}

Choose a reason for hiding this comment

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

) is missing at the end here ;)

README.md Outdated Show resolved Hide resolved
@atinux
Copy link
Owner

atinux commented Nov 21, 2024

I did not forget, will have a deeper look next week as I want to be confident with the API changes.

@patrick-hofmann
Copy link
Author

No problem, take the time you need

@thewebartisan7
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants