nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Support configured sessions

Open pi0 opened this issue 1 year ago • 2 comments

H3 provides a useSession(event, config) utility which is useful to support authentication flows however its usage within Nitro apps is not intuitive because config needs to be manually handled and added.

We can support a Nitro configuration (which can be overridden with conventional runtime configs) for configured sessions.

To be used for upcoming h3 useSession(event, name = "default") (https://github.com/unjs/h3/issues/693)

pi0 avatar Mar 06 '24 11:03 pi0

So we could set this runtimeConfig:

runtimeConfig: {
  session: {
    default: {
      name: 'my-session',
      password: 'my-password-for-default-session'
    }
}

Looks great to me!

atinux avatar Mar 06 '24 13:03 atinux

Ye. I think putting the session definitions in nitro.config (or nuxt.config) And only for password use runtimeConfig/process.env.SERVER_SESSION_DEFAULT_PASSWORD.

Having definitions at built-time we can have more integrations and better predictable behavior for example for generating OpenAPI docs.

pi0 avatar Mar 06 '24 14:03 pi0