Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set axios token for authorization #31

Closed
ImadBoumzaoued opened this issue Jun 16, 2017 · 9 comments
Closed

How to set axios token for authorization #31

ImadBoumzaoued opened this issue Jun 16, 2017 · 9 comments
Labels

Comments

@ImadBoumzaoued
Copy link

ImadBoumzaoued commented Jun 16, 2017

Hello sorry to make this an issue, I've tried to make this work

Exposes setToken function to $axios so we can easily and globally set authentication tokens.

but without any luck can you please explain how to make it work form a store mutation.

Thanks a lot

This question is available on Nuxt.js community (#c38)
@pi0
Copy link
Member

pi0 commented Jun 16, 2017

Hi. Sorry for currently lack of it's documentation. Actually i've just left it until auth module is ready. For setting authentication token, anywhere that you have access to $axios (see docs) can call like this:

// This will add `Authentication: Bearer ....`  header to all requests
$axios.setToken('Token from API or Cookies', 'Bearer')

@pi0 pi0 added the docs label Jun 16, 2017
@ImadBoumzaoued
Copy link
Author

ImadBoumzaoued commented Jun 16, 2017

Hey thanks for the reply, I don't know what I'm doing wrong but when I do it like this

this.$axios.setToken(token, false)

I get setToken is not a function, knowing that this.$axios.post is working

@pi0
Copy link
Member

pi0 commented Jun 16, 2017

Hmm i can't test now but seems it should be attached to prototype instead until bug resolved please use an alternative like this: $axios.defaults.headers.common.Authorization= toekn

@ImadBoumzaoued
Copy link
Author

Ok I'll use the alternative solution.
Thanks a lot :)

pi0 pushed a commit that referenced this issue Jun 19, 2017
@pi0
Copy link
Member

pi0 commented Jun 19, 2017

setToken docs are ready and working :)
https://github.com/nuxt/modules/tree/master/modules/axios#helpers

@pi0 pi0 closed this as completed Jun 19, 2017
@Mr-Black-Dahlia
Copy link

@pio the link leads me to a 404

@Flyer3d
Copy link

Flyer3d commented Jun 14, 2018

@pi0 Link doesn't work! 404

@kaungmyatlwin
Copy link

@indiecore-fm @Flyer3d https://auth.nuxtjs.org/api/auth.html

@rahul9874563210
Copy link

@kaungmyatlwin can you give example using nuxt/auth module for external API authentication with custom function.

detail issue is here
nuxt-community/auth-module#216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants