Skip to content

Instantly share code, notes, and snippets.

@MrNaif2018
Last active January 19, 2020 19:37
Show Gist options
  • Save MrNaif2018/f36b3cc3ccd162749ee4b026e73d5a50 to your computer and use it in GitHub Desktop.
Save MrNaif2018/f36b3cc3ccd162749ee4b026e73d5a50 to your computer and use it in GitHub Desktop.
Authentification using @nuxtjs/auth(JWT with refresh tokens)
this.$axios.post('/token', {
email: this.email,
password: this.password
}).then((resp) => {
this.$auth.setToken('local', 'Bearer ' + resp.data.access_token)
this.$auth.setRefreshToken('local', resp.data.refresh_token)
this.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access_token)
this.$auth.ctx.app.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access_token)
this.$axios.get('/users/me').then((resp) => { this.$auth.setUser(resp.data); this.$router.push('/') })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment