-
Notifications
You must be signed in to change notification settings - Fork 117
Client should ensure socket.io upgrade is complete before authenticating #275
Comments
Also the code below seems not to work (params are never set):
|
I'm not sure what |
It is working in REST as expected but using socketIO, token is not sent to the server at all. Shall I provide you with some code? |
Yes please. Maybe a repository to reproduce. I have definitely used authentication and service requests with Socket.io before. |
I have created a simple featherjs app: https://github.com/zender/feathers-285 REST provider is working without any problems but socketio is not sending the token. feathers-client does not read token from local storage (I had to set it manually) - https://github.com/zender/feathers-client-285/blob/master/src/app/shared/services/rest.service.ts#L36 Also hooks are not working either on the client side: https://github.com/zender/feathers-client-285/blob/master/src/app/shared/services/rest.service.ts#L25 Thank you in advance for your support. |
I have the same problem, I am logged in rest but not in socket, I get an error 'token missing'. So it would be nice to reconnect the user to the socket with cookies. |
I # with facebook JS SDK in react app, after I use facebook-token passport strategy, it's work but if I also use a socket connection for a chat I'm not connected, how to connect the socket after a rest connection? On client-side I noticed that we can't connect with socket on social provider: |
any updates??? |
I would recommend using a basic feathers example that works for you, then modifying what you need on top of that. |
When i deploy a feathers application, the token gets set automatically when I access through the feather services, but get a 401 when doing it any other way. |
For anybody having this issue, please make sure that your socket.io connection's upgrade process has fully stabilized before you call authenticate.
If you call authenticate right when socket.io connects, and you haven't locked the transports to const feathers = require('feathers/client')
const socketio = require('feathers-socketio/client');
const hooks = require('feathers-hooks');
const io = require('socket.io-client');
const authentication = require('feathers-authentication/client');
const socket = io('http://api.my-feathers-server.com', {
transports: ['websocket']
});
const app = feathers()
.configure(hooks())
.configure(socketio(socket));
.configure(authentication({ storage: window.localStorage }));
app.authenticate(); The downside to the above is that it won't work with clients that aren't compatible with WebSockets. So, the alternative would be to make sure you authenticate after the transport upgrade has occurred: const feathers = require('feathers/client')
const socketio = require('feathers-socketio/client');
const hooks = require('feathers-hooks');
const io = require('socket.io-client');
const authentication = require('feathers-authentication/client');
const socket = io('http://api.my-feathers-server.com', {
transports: ['websocket']
});
const app = feathers()
.configure(hooks())
.configure(socketio(socket));
.configure(authentication({ storage: window.localStorage }));
socket.io.engine.on('upgrade', function(transport) {
console.log('transport changed');
app.authenticate();
}); See this Stack Overflow answer for more examples. |
You have to authenticate after the transport upgrades. See feathersjs-ecosystem/authentication#275
@marshallswain @daffl maybe we should do this inside the client itself. |
I think so. It's something that you would want in every app, I think. |
Ya I agree. Going to change the title on this. |
Issue moved to feathersjs/feathers-authentication-client #4 via ZenHub |
I have the following code in Angular 2:
authenticate() method works fine but when I try to call getResource("some service") .someMethod then it says that token is missing.
Any suggestion how to fix that?
The text was updated successfully, but these errors were encountered: