You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My backend API is having basic auth added to it, so instead of passing the token in the Bearer auth header, I need to pass it either in the body of all requests, or appended in the URL of all requests. All requests need to have the basic auth header added also.
I am having trouble with this on the server side. I have an axios inteceptor which works on client-side but not server-side.
The relevant part of my login code looks like this, and you can see I am storing the token in universal storage:
constres=awaitctx.$auth.login({ data })if(!res.data||!res.data.errors)ctx.$auth.setUser(res.data.data.user)ctx.$auth.$storage.setUniversal('token',res.data.data.token,true)
The inteceptor in the auth plugin then retrieves the token from storage and appends to the URL being called by axios:
$axios.onRequest((config)=>{consttoken=$auth.$storage.getUniversal('token')if(token)config.url=config.url+'?token='+token// TODO: add basic auth to config.headers})
I am seeing the token come through appended to the URL on client requests, but when I hit refresh and the application calls get user, the inteceptor is not being called.
After some debugging it seems that the plugin referenced in auth.plugins is not called on the server-side. I have another plugin with an axios inteceptor that is referenced in the plugins property of the nuxt.config.js file. If I add a console.log call to both inteceptors, I see that the auth plugin's inteceptor does not fire when I hit refresh, it only fires when I make a client-side request.
So I'm lost now. Can somebody tell me how I can pass both the token and basic auth header to the server all requests?
This discussion was converted from issue #1413 on January 18, 2022 10:40.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My backend API is having basic auth added to it, so instead of passing the token in the Bearer auth header, I need to pass it either in the body of all requests, or appended in the URL of all requests. All requests need to have the basic auth header added also.
I am having trouble with this on the server side. I have an axios inteceptor which works on client-side but not server-side.
Here's my config:
The relevant part of my login code looks like this, and you can see I am storing the token in universal storage:
The inteceptor in the auth plugin then retrieves the token from storage and appends to the URL being called by axios:
I am seeing the token come through appended to the URL on client requests, but when I hit refresh and the application calls get user, the inteceptor is not being called.
After some debugging it seems that the plugin referenced in
auth.plugins
is not called on the server-side. I have another plugin with an axios inteceptor that is referenced in theplugins
property of thenuxt.config.js
file. If I add a console.log call to both inteceptors, I see that the auth plugin's inteceptor does not fire when I hit refresh, it only fires when I make a client-side request.So I'm lost now. Can somebody tell me how I can pass both the token and basic auth header to the server all requests?
Beta Was this translation helpful? Give feedback.
All reactions