Auth-module: Manully setting up user token setToken()

Created on 8 Aug 2018  路  3Comments  路  Source: nuxt-community/auth-module

What problem does this feature solve?

When a token is added manually Axios doesn't attach the token. As for my auth flow it is required.

What does the proposed changes look like?

When setting a token manually using $auth.setToken calling this.$auth.ctx.app.$axios.setHeader(this.options.tokenName, token) this would solves the manual login problem.

This feature request is available on Nuxt community (#c184)
enhancement implemented

Most helpful comment

I also need this feature for registering in or logging in via a password reset.

I got around this by using:

this.$auth.setToken(this.$store.state.auth.strategy, `Bearer ${data.access_token}`)
this.$auth.strategy._setToken(`Bearer ${data.access_token}`)
return this.$auth.fetchUser()

I am going to open a PR with this as a helper function.

** edit
https://github.com/nuxt-community/auth-module/pull/278

All 3 comments

I also need this feature for registering in or logging in via a password reset.

I got around this by using:

this.$auth.setToken(this.$store.state.auth.strategy, `Bearer ${data.access_token}`)
this.$auth.strategy._setToken(`Bearer ${data.access_token}`)
return this.$auth.fetchUser()

I am going to open a PR with this as a helper function.

** edit
https://github.com/nuxt-community/auth-module/pull/278

This issue is not resolved by #278. setUserToken() works just fine on it's own, but setToken() still doesn't set the axios auth token.

Closing here as auth v5 can set tokens using this.$auth.strategy.token.set(...)

Was this page helpful?
0 / 5 - 0 ratings