Relogging in?
Closed this issue · 3 comments
I am trying to be able to login my users. I have saved my refresh token and use that in this function... but it wont work. What else do I need to login to firebase after a user closes and opens back up my application?
Here is my full login script. After it get's the refresh token it saves it to a file. Then when it needs to login again it pulls the refresh token out and sends it to handleRefreshToken
private function handleRefreshToken(refreshToken:String):void
{
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
var myObject:Object = new Object();
myObject.grant_type = "refresh_token";
myObject.refresh_token = refreshToken;
var request:URLRequest = new URLRequest("https://securetoken.googleapis.com/v1/token?key="+FIREBASE_API_KEY);
request.method = URLRequestMethod.POST;
request.data = JSON.stringify(myObject);
request.requestHeaders.push(header);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, refreshTokenLoaded);
loader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
loader.load(request);
}
private function refreshTokenLoaded(e:Event):void
{
e.target.removeEventListener(Event.COMPLETE, refreshTokenLoaded);
var rawData:Object = JSON.parse(e.currentTarget.data);
if (rawData.access_token == null)
{
toggleContent(0);
toggleIntro();
Dialog.service.toast("There was a problem logging you in. Please try again.");
FirebaseCrash.service.report(new Error("Login Error", 0));
}
else
{
authToken = rawData.access_token;
trace("REFRESH TOKEN LOADED.");
trace(e.target.data);
trace("Init tutorial");
if (signingIn)
{
toggleContent(CONTENT_FRAME);
toggleHomeScreen();
}
else
{
//Init bio fill//
toggleProfile(true);
}
}
Your code looks fine, very similar of the one I use.
What is the error you get?
You can try to copy the heuristic from Todo App:
https://github.com/PhantomAppDevelopment/todo-app/blob/master/src/Main.as
I made the process easier by creating a utility class to handle the profile management.
Found out that I was logging in just fine. I just wasn't saving my uid and the app would bug out. My mistake.
No worries, it happens to us all.