nuxt-community / auth-module

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

Prevent clearing storages on loginWith error #1817

Open GabrielHangor opened 1 year ago

GabrielHangor commented 1 year ago

Hello guys.

I've searched for the answer in the docs and even through the actual codebase but couldn't find if it is possible to prevent clearing storages on login attempts if error happens.

For example, i have the following method for authorizing the user inside my API service :

  async authorizeUser(phoneNumber, verificationCode) {
    await this.$auth.loginWith('local', {
      data: { phone: phoneNumber, verification_code: verificationCode },
    });

If credentials are ok and there is no error, tokens are added to the localstorage and cookies, vuex state is set to loggedIn and everything is working fine.

However, if the user is already signed in and wants to, for example, use other data (ex new phoneNumber) and attempts to log in with the new phoneNumber and verification code and an error happens for some reason (incorrect code or whatever), all his previous tokens (auth and refresh tokens from localstorage and cookies) get deleted.

Is it possible to avoid such behaviour and just do nothing instead of clearing all the storages?

Regards.

Nuxt config if needed. image

alihippo commented 1 year ago

Same issue on my project