简体   繁体   中英

Using nuxt.js auth with multiple app in the same PC

I have two apps using auth module and nuxt.js running in my PC. I am used auth local strategies at both app.

I have a problem when I am logged(authenticated) in my first app, the second app doesn´t ask for authentication(both apps in same PC).

I have to delete the localstorage with auth data, in order to my second app ask for login to authenticate.

My nuxt auth settings is in the nuxt.config.js is:

auth: {
    localStorage: {
      prefix: 'auth.',
    },
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'data.access_token',
          maxAge: 1800,

          type: 'Bearer',
          required: true,
        },
        refreshToken: {
          property: 'data.refresh_token',
          maxAge: 60 * 60 * 24 * 30,
        },
        user: {
          property: 'data',
          autoFetch: true,
        },
        endpoints: {
          login: {
            url: 'user/login',
            method: 'post',
          },
          refresh: { url: 'user/refreshToken', method: 'post' },
          user: { url: 'user/me', method: 'get' },
          logout: false,
        },
      },
    },
    redirect: {
      login: '/login',
      logout: '/login',
      // callback: '/dash',
      // home: '/clientes',
      home: '/',
    },
  },

Is there some special settings in the config to avoid it I have tried to use a different localstore prefix, but no look

NuxtJs has localStorage enabled by default as a session persistence engine.

auth: {
  localStorage: {
    prefix: 'auth.'
  }
}

You need to provide a different prefix in your localStorage configuration (of course, if you intend to continue using localStorage) for each of your projects. That should make sure both apps don't look for the session token in the same key.

This is what you're looking for https://auth.nuxtjs.org/api/options/#localstorage

There's an option for cookies as well, but the logic remains the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM