Skip to content

Connecting after authentication #64

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

Closed
jrthib opened this issue Jun 19, 2014 · 7 comments
Closed

Connecting after authentication #64

jrthib opened this issue Jun 19, 2014 · 7 comments
Labels

Comments

@jrthib
Copy link

jrthib commented Jun 19, 2014

I have an angular app with a login form. Once authenticated my auth service will forward to the inner protected state of the Angular app. Within this, I would like to have the web socket open it's connection. Currently to achieve this I have to refresh the page after authenticating, then the socket connection occurs.

Do you have any recommendations on how to achieve this?

@btford
Copy link
Owner

btford commented Jun 19, 2014

Without knowing how your authentication works, I can't offer any definitive advice.

I'm assuming you have some sort of server-side flow that sets cookies as a response back from the server which is why you need to refresh.

As far as angular-socket-io is concerned, there's no reason you can't invoke the socketFactory after some auth handshake with the server.

@jrthib
Copy link
Author

jrthib commented Jun 19, 2014

That is actually quite helpful, and yes that is exactly correct. I set some cookies based on the response from the server. How would I go about invoking the socketFactory later? Right now I'm including it in a controller that shouldn't get used until you move to an inner page.

@btford
Copy link
Owner

btford commented Jun 20, 2014

One option is to use resolve in your routes. Another would be to have a service that returns a promise that eventually resolves to the socket instance once the auth finishes.

@jrthib
Copy link
Author

jrthib commented Jun 20, 2014

Great thanks! I'll give these a try.

@jrthib
Copy link
Author

jrthib commented Jun 20, 2014

I ended up creating a promise in my socket factory that resolves after authentication when it receives an event broadcast from the auth service. Seems to be working good so far.

@jrthib jrthib closed this as completed Jun 20, 2014
@btford btford added the faq label Jun 20, 2014
@jrthib
Copy link
Author

jrthib commented Jul 16, 2014

Here's an example: https://gist.github.com/jrthib/4ce016449a29811d71b5. I hope this helps!

On Jul 16, 2014, at 6:59 PM, Dadocat notifications@github.com wrote:

Any chance to have a sample example for the promise you implemented in your factory ? Thanks a lot


Reply to this email directly or view it on GitHub.

@Razgort
Copy link

Razgort commented Mar 10, 2016

Like it is said here : https://github.com/rakeshok/socket.io-client-cookie
If you want to check for authentification you need to get the cookie. Or socket.io-client does not allow to send cookies apparently ....
If someone find a fix or a wait to use the patch in angular, I'll take it =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants