-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Allow set token with a function and fix a error #8
Allow set token with a function and fix a error #8
Conversation
@Akhail thanks for this! I need this badly! I have a question though, how do I call this setAuthentication after having already initialized the plugin? I initialize it as part of my store.js
then later when my user actually logs in, I want to set the authorization token at that point. How can I access the plugin instance at that point? And also.. how can I achieve this for now since this PR has not been accepted yet. Thanks a lot!! |
@vesper8
without this.. i don't know, because this package uses a separate instance of axios, so it is impossible to access it. |
thanks for the quick reply @Akhail I just tried out your fork and unfortunately it doesn't work out for me.. I also don't understand how this could work for you. How can you access the user's token from within that callback? You can't even access 'this'.. let alone the $auth global that has access to the token I use @websanova/vue-auth to handle my jwt login/access and I tried doing this:
It tells me that $auth is not accessible. this is not accessible either. In your mock example you refer to a variable "login" but how could you even have access to that in the scope of your store.js ? |
Oh my.. I kept reading and trying things and I guess I got lucky.. this works!
I also discovered this awesome package here https://github.com/ds300/patch-package which lets you create a patch super easily so you don't have to rely on forks when fixing/adding features such as in this case Anyway your method works awesome and is much needed @Akhail ! Thanks a lot for helping put me on the right patch and for this PR! @kiaking @KaniRobinson please please merge this PR!! |
For those wondering how to get the token from something like nuxt auth-module, I'm getting it from localStorage:
Thanks to @go4cas in the Slack channel for this suggestion. |
For Nuxtjs, I have to create plugin and use that plugin (in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Job Dude, Sorry for the lack of response
This "pull requests" fix an uncaught exception that occurs in a network error, because the response does not have the "status" property. It also allows you to configure the "access token" as a callback function and as a string of course