auth-module icon indicating copy to clipboard operation
auth-module copied to clipboard

runtime config support for auth options

Open wensaint opened this issue 3 years ago • 2 comments

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 avatar Jun 17 '22 09:06 wensaint

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.

wensaint avatar Jun 24 '22 08:06 wensaint

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

CaptainFalcon92 avatar Jan 31 '23 17:01 CaptainFalcon92