-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
"No auth token" error on service calls #892
Comments
There are several other issues about authentication on socket reconnection. I will probably tackle all of them for the next version I am currently working on. Directly related is probably #854 |
@daffl Thanks for the response. Is there any way you can think of to mitigate this or work around it? For some users of our (react native) app, the no-auth token happens far more frequently than others. On certain devices, users can't signup/login or post content because of how consistently it's happening. |
Are you using the recommended Socket configuration for React native? const socket = io('http://api.my-feathers-server.com', {
transports: ['websocket'],
forceNew: true
}); |
@daffl I'm going to confirm with Eli but I believe the following is how we've setup our socket configuration (in our mainstore doc).
Our mainstore (which contains our service calls) is quite a big file at the moment, if you'd like I can share that with you over PM. |
We've deployed an update with the correction. We believe this may resolve the issue for us. We'll confirm as soon as our users do. |
Unauthenticated requests on reconnection are probably still an issue but it should happen very rarely. I don't think we ever noticed it as a major issue in our React Native applications (as long as the |
Closing since it appears to be solved. |
It is. Thanks @daffl |
It seems like we're still experiencing this issue even after implementing the recommended Socket configuration that @daffl posted above. For some of our users it happens quite often. Is there something else that could be causing it? Any help would be appreciated. I'd be willing to share more of our code if that would be helpful. |
@daffl if you would like access to our git repo just let us know and we can share it with you. |
Hi @daffl, we shared our repo with you just in case. |
I will do my best to provide some more information that may help to reproduce, test and solve the problem. As more users are onboarding, we're noticing Android users are impacted in particular but this does occur for iOS users as well. One of the troubles with isolating the root cause is that it is intermittent and appears to increase in frequency with bad network connections or when switching networks (wifi/data). Here are the different instances in which timeouts appear:
We're not entirely sure if the either instance shares the same root cause but it is our suspicion (after getting a lot more feedback from users) that the issues described before simply did not go away after implementing "transports: ['websocket'], forceNew: true" but simply decreased in frequency on our own test devices at the time. My best hypothesis is that we still require some other form of failsafe to reconnect/authenticate the client with feathers. It's as if the service call isn't happening in the right order (even though it seems like it should). I have experience working with websockets before but not to the extent of using it to handle every single request from client to server for multiple types of services so I feel under-qualified to judge. Network type and integrity is impacting our ability to reproduce the issue so we discovered that we had to turn on network congestion emulation to even reproduce the issue at times (given how good our connection is at work). We have been able to reproduce this with another simpler setup than our own. |
Been experiencing this issue a lot recently. |
This issues is probably the same as https://github.com/feathersjs/authentication/issues/577 I think I mentioned somewhere else, that this issue is probably caused somewhere in https://github.com/feathersjs/authentication/blob/master/lib/socket/update-entity.js#L3. The socket disconnects, deletes all properties but does not re-authenticates on reconnection. Since the original authors are unfortunately unavailable to debug this more, the only way I see to move this forward is the fix in the next auth version I am working on in this branch. |
@daffl Is it ready for testing? We'd be happy to test it. |
FWIW I have resolved this in my app by manually (re-)authenticating on the client side on load |
@homerjam @8BallBomBom would either of you be able to share examples of what you're doing to re-connect and/or re-authenticate? |
@pribeh https://gist.github.com/homerjam/4bdd2afa4af5f712fcc7b4dc2391583e#file-plugins-auth-js-L32-L46 I'm basically grabbing the cookie and calling |
@pribeh Don't really have much to show. |
Our app has a functionality that allows users to tap on a chat notification while the app is in the background to immediately open up that chatroom, but there is an issue where there is frequently a timeout error whenever the app tries to load the chat messages when doing this. I tested out the following code to re-authenticate whenever our app returns from the background, and while it authenticates successfully the service calls to load chat messages still fail.
My theory is that when loading the chat messages, the server performs multiple nested service calls that require authentication and the authentication payload isn't properly being passed to one of them which causes the service call to fail. What doesn't make sense though is that this rarely happens normally, but it almost always happens when the app returns to the foreground from tapping on a chat notification. I'm guessing that the app disconnects from the server after it's been in the background long enough, and when returning from the background the service call to fetch the chat messages triggers before the re-authentication can complete, causing the service call to fail. However, we still occasionally get these |
@EliSadaka do you need an |
Well I am not sure if this is relevant and will help but here are some insights from our experience since we also experimented this kind of socket re-connection issue, especially when running on mobiles (eg with app in background or unstable network connection). Due to async operations the client logic can be really complicated in SPA. Let's say your app requires user data (thus authentication) and you have a couple of pages where you gather data from a couple of services. First you must ensure that when performing a reload from any page everything goes always as expected (you often have random behaviors with async ops). Otherwise you have an async issue in your own business logic. Once you are ok with this, you must then ensure that upon socket re-connection you don't need to re-run this business logic, notably with real-time apps. Indeed I doubt that simply reconnect the socket on the backend side under-the-hood will cover all use cases: during the connection failure a lot of things could have happened on the backend leading to inconsistent state of the client. You at least need to send an event to the client saying "hey we have reconnected" so that the business logic can be run again to update the client state whenever required, which is almost equivalent to a "thin page reload". In hybrid mobile apps things can be worse because you don't really control what the system does under the hood, it might perform a full page reload or whatever. In our production app we ended in performing a complete reload on re-connection https://github.com/kalisio/kApp/blob/master/src/components/Index.vue#L74 to make things easy (but we ensured that reload work as expected first). I am not saying it is the best thing to do but it improved our user experience. |
@EliSadaka I'm doing something similar but what i found was calling disconnect on the socket directly every time the app went into the background was the best solution. |
@EliSadaka I had a quick look to your repo and I am not sure your are doing async ops right in your store, don't mix await and promises this might not work as you expect: https://hackernoon.com/a-common-misconception-about-async-await-in-javascript-33de224bd5f. |
By the way which Feathers version are you using ? Indeed, this might be related #979. |
On our server we have the following packages: @feathersjs/feathers: 3.1.7 On our client we have the following packages: @feathersjs/feathers: 3.1.7 |
Has there been any development on this? I am using Nuxt+FeathersJS and I have been running into the same issue of 'No Auth Token' ` export const host = process.env.API_HOST || 'http://localhost:3030'; export default (origin, storage) => { const feathersClient = feathers() return feathersClient; |
I traped for this error for whole day, and finally find the solution npm install cookie-parser - - save var cookieParser = require('cookie-parser') app.use(cookieParser()) |
This should be fixed in the new authentication client of Feathers v4. See the Migration guide for more information on how to upgrade. |
Is this still valid and you never experience the same error again? |
Steps to reproduce
I'm experiencing an issue where frequently when performing a service call an authenticated user will seemingly lose authentication for a second, causing the service call to fail. After that it looks like they are re-authenticated, but that one service call is lost. The server logs show a
"No auth token"
error on thebefore
hook of whatever service was called when this occurs. At first I thought the problem was caused by calling other services within a hook and not passing the authentication params to them, but looking at the logs the server produces this error happens even when the only hook on the called service isauthenticate('jwt')
.I'm not sure what the relevant code that could be causing this issue is. Here is what my
authentication.js
looks like:Here is my
channels.js
:Here is what I have on the client side in regards to authentication:
If there's any other code you think may be causing the problem and you'd like to look at just let me know.
Expected behavior
The service call should complete successfully.
Actual behavior
The service call fails and returns a
"No auth token"
error.System configuration
Module versions (especially the part that's not working):
Server:
@feathersjs/authentication: 2.1.5
@feathersjs/authentication-jwt: 2.0.1
@feathersjs/authentication-local: 1.2.1
@feathersjs/configuration: 1.0.2
@feathersjs/errors: 3.3.0
@feathersjs/express: 1.2.2
@feathersjs/feathers: 3.1.5
@feathersjs/socketio: 3.2.1
Client:
@feathersjs/authentication-client: 1.0.2
@feathersjs/client: 3.4.5
@feathersjs/feathers: 3.1.5
@feathersjs/socketio-client: 1.1.0
NodeJS version: 9.11.1
React Native Version: 0.55.4
The text was updated successfully, but these errors were encountered: