Hi Leonid, I'll look into this for you and be back with an answer soon.
Best Regards, Patrick.
+1 for this
Using with an angular app and if the app is reloaded by a refresh there needs to be way to use the token system to keep the user logged in
this.getAuthToken = function(){ return authToken; }
In this.init function, add before cleanup() and connect() calls:
this.init = function(options) { ... errorCallback = options.onError; nonceCallback = options.onNonce; cleanup(); connect(); };
You can now now get authToken and sessionId from the cookies or whatever place you store them, and pass them to the options for the init function.
After user is logged in, you can get them by calling getSessionId() and getAuthToken().
In Angular.js, I have a service that wraps up the GameSparks SDK. In that service, I get saved authToken and sessionId using $cookies.get(), inject them into my options, init gamesparks, and then call AccountDetailsRequest. If that succeed, I get all necessary information and assume that user is logged in, otherwise I show the login page. In the login controller, after user signs in using AuthenticationRequest, I call getSessionId() and getAuthToken and save them into cookies using $cookies.put(). Hope that helps someone.
That would be really nice to have that changes in the official gamesparks.js.
Leonid thanks for your post. It was something I was leaving to the end of my development to look into and your post has saved me having to look so thank you for taking the time.
Cheers
Hi all, I'm trying to achieve the same, I just need to keep the user logged in in my JS app. I'm not familiar with Angular and I don't understand how to wraps the Gamesparks SDK in an Angular service, do you have maybe a sample for this? For now if the user is logged in and jumps to another page I call AccountDetailsRequest but of course the connection with the socket was lost and a can't catch user's data.
I was looking into the same topic. Update on that matter:
The functionality described by Leonid Umanskiy is included in the latest js sdk. The only thing you need to do is to store the authToken and set it before initializing. Works like a charm for me.
Use:
getAuthToken setAuthToken
Does that apply for the CS version?
Leonid Umanskiy
I know that you can use DeviceAuthenticationRequest but we need to authenticate existing user using his login and password first, and then keep the session.
We are building a custom dashboard using JavaScript SDK and we want to have "remember me" option. It seems that currently, once the WebSocket is disconnected, there is no other way to re-authenticate user besides asking for a login and password again, and this really annoying for the user (every time they refresh the page, they need to enter login and password again).
If there is currently no such option, can we expect to have it in the near future?
Thanks!
1 person likes this idea