nuxt-alt / auth

An alternative module to @nuxtjs/auth
https://nuxt-alt-auth.vercel.app/
MIT License
96 stars 20 forks source link

feat: support public runtime config strategy updates #14

Closed hendrikheil closed 1 year ago

hendrikheil commented 1 year ago

This PR aims to make strategies configurable at runtime. It adjusts the plugin template to merge the static strategy configuration from nuxt.config.ts with optional strategy configuration from the public runtime config.

Assuming the following nuxt.config.ts file:

export default defineNuxtConfig({
  auth: {
    strategies: {
      myStrategy: {
        scheme: 'openIDConnect',
      },
    },
  },
  runtimeConfig: {
    public: {
      auth: {
        strategies: {
          myStrategy: {
            clientId: '',
            endpoints: {
              configuration: '',
            },
          },
        },
      },
    },
  },
});

This would now allow you to configure things like the clientId for strategy myStrategy with an environment variable called NUXT_PUBLIC_AUTH_STRATEGIES_MY_STRATEGY_CLIENT_ID.

You can also adjust things like the configuration endpoint with this approach.

This is particularly useful for deployments where you need to change the client id depending on the environment. Development, Staging and Production environments would now be easily configurable by changing the .env file or environment.

This PR resolves https://github.com/nuxt-alt/auth/issues/2