-
Notifications
You must be signed in to change notification settings - Fork 19
No Auth header added when sending 1st request #80
Comments
You have to call |
Thanks for the reply. Got confused by the docs here, for this
Sounds like it will send a request to validate the identity? (in my case, jwt) After reading the source code, as you said, if no option is given, it just returns the jwt. so, maybe a better way to do this is in the client side hooks? Like a setup. Such that, later on, we can just call the service. And, I think the doc should add the proper steps for calling an auth-needed API? but why it works the 2nd time?..... |
So, following my previous code snippet, I add the const result = await client.authenticate();
console.log('result-->', result);
const swaps = await swapService.find(); Where the const client = feathers()
.configure(hooks())
.configure(rest().axios(axios))
.configure(auth(authConfig));
const swapService = client.service('swap'); The problem is the 2nd line never gets executed...Anything I did wrong here? The example from the doc shows how to grab the value from the JWT and then use it as a parameter when calling the service, what I want is to add the Rather than doing this by myself, like client.hooks({
before: {
all: [
hook => {
const apiKey = window.localStorage[authConfig.storageKey];
if (apiKey) {
hook.params.headers = { [authConfig.header]: `${apiKey}` };
}
}
]
}
}); What's the Or is there a client-side service level hook that I can add header only to the service I want. |
That probably means you are getting an error.
|
You are right. I forget to turn of the mongodb...... :D And there is no error message for this. Now it works. But it will send an extra request, when is the proper timing to do this? I think I don't need to call the |
You do. This is to handle socket and HTTP authentication the same way and to explicitly being able to deal with expiration and login error separately. All Feathers chat frontends (e.g. https://github.com/feathersjs/feathers-chat/blob/master/public/vanilla/app.js) show how it should be used. |
Understood. But seems it should give the And why the 2nd request could have the auth header, isn't this an inconsistent behavior? |
I added the But it seems that it won't work unless I call the await client.authenticate();
const swaps = swapService.find(); Which looks like I need to do this every time I want to send a request? Besides this, info: after: users - Method: get
info: after: swap - Method: find If I call the info: after: users - Method: get
info: after: authentication - Method: create
info: after: users - Method: get
info: after: swap - Method: find Which means a separate request has been sent, and it seems that it refreshes the And if we gonna do it every time before we sending a request, looks like not that good. What do you think? :) Or I did something wrong? |
It only needs to be done once when the page is initialized. Have a look at how the React chat application does it (here) |
Thanks for the answer. It seems that In my code, according to my Maybe websocket's faster speed causes it to behave differently here. I use |
Steps to reproduce
I have a service which has a
authenticate('jwt')
at itsbefore.all()
hook.In my
React
app, in thecomponentDidMount
I send a request to this endpoint from feathers client,swapService.find()
, it gives meNo Auth token
error(401), it's weird because there are tokens both at cookie and local storage.Put this aside, when the user press
Refresh
button, the component will send a request using the same code before, this time it could get the expected result without any problem….This is the
feathers-client
settings:This is the
redux action
for handling the request thing:When the client starts, the 1st request will be sent:
And this
this.props.loadList()
will be invoked again when the user press therefresh
button (Which will be shown when there is an error like thisno auth token
.).It will work if I add this:
Got this after I read #48
Is this a bug or I setup something wrongly? Glad to help if it's a bug. :)
Expected behavior
Consider the token is just there, the 1st request from
componentDidMount
should get the list.Actual behavior
The 1st one always fails while the 2nd always succeed.
System configuration
Module versions (especially the part that's not working):
all latest
NodeJS version:
Node 8.9.0
Operating System:
OS X 10.13.1
Browser Version:
Chrome 62.0.3202
Module Loader:
latest
create-react-app
The text was updated successfully, but these errors were encountered: