nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

runtime config support for auth options #1765

Open wensaint opened 2 years ago

wensaint commented 2 years ago

Is your feature request related to a problem? Please describe.

my project need one build, muti deploy.

currently i use cookie(localStorage will be the same) to save auth token, but the auth options is build in during build process.

// nuxt.config.js
auth: {
     cookie: {
       prefix: `${process.env.PROJECT_CODE}.`,
       options: {
         path: process.env.PUBLIC_PATH,
         maxAge: 2 * 3600
       }
     },
     ...
}

so if i deploy muti sites in the same domain, user login in site A will be able to access site B without login.

Describe the solution you'd like to see

If i can config auth within RuntimeConfig (either publicRuntimeConfig or privateRuntimeConfig), the options can be change at runtime, then every site will have unique cookie, it will be great.

// nuxt.config.js
publicRuntimeConfig: {
    auth: {
      cookie: {
        prefix: `${process.env.PROJECT_CODE}.`,
        options: {
          path: process.env.PUBLIC_PATH,
          maxAge: 2 * 3600
        }
      }
    }
  }
wensaint commented 2 years ago

I find the solution by change the source code.

filePath : src/core/storage.ts 
line: 29
// this.options = options

// add runtimeConfig support by wensaint
this.options = {
  ...options,
  ...(this.ctx.$config && this.ctx.$config.auth)
}

Current I fixed this at my folk: https://github.com/wensaint/auth-module I hope this will be accepted in the future.

CaptainFalcon92 commented 1 year ago

We are quite probably several thousands in the need for this runtimeConfig support. It is a basic requirement for any nuxt module now.

Is there still someone maintaining this repository ? Please we would appreciate an update, a merge of what as been proposed many time, i would add a lot to the auth-module.

I will be honest, waiting for you to support runtime config, i made my own auth layer :( What @wensaint showed, could it be applied ?

Thank you maintainers