Ionic/Firebase: Log in after logging out doesn't work - ionic-framework

I am building an Ionic/Phonegap app with a Firebase backend.
Login
Followed the example from the official AngularFire documentation for login:
// Check sign-in data
$scope.signIn = function(user, password) {
// Log in
$scope.auth.$authWithPassword({
email : user,
password : password
})
// If successful
.then(function(authData) {
console.log('worked');
// Further code
}
// If failure, alert
.catch(function(error) {
console.log(error);
}
}
Login works fine.
Logout
For logout I also copied the example from the documentation:
$scope.logout = function() {
// Manually disconnect from database
Firebase.goOffline();
// Log user out
$scope.auth.$unauth();
// Go to landing page
$state.go('signin');
};
Seems to work as well (when I'm asking for the current authentication state of the user after logging out $getAuth() returns null).
Login after Logout
But if I'm now trying to log in again, nothing happens - no error, no success message. So neither of the console.logs triggers.
I need to close and open the app again or refresh the browser window in order to be able to log in again. Can anyone tell me what I'm doing wrong here?
Versions
Using the latest versions:
Ionic 1.2.4
Firebase 2.4.0
AngularFire 1.1.3

Remove the Firebase.goOffline() from your logout. If you want to manually manage Firebase connection then you should consider adding Firebase.goOnline() during login.
Auth.$unauth() will take care of logging out the user, you do not have to disconnect Firebase manually.

Related

Firebase Authentication using facebook and google signin not working when internet is turned off and turned back on

I have a strange issue with firebase authentication. SigninCredential callback never gets called when I turn off and turn back on the internet. Only after a few hours(probably after 4 hours) callback gets triggered
val mCredential = FacebookAuthProvider.getCredential(mAccesstoken!!.token)
mFirebaseAuth.signInWithCredential(mCredential)
.addOnCompleteListener(this) { it ->
if (it.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
getCurrentUser(mFirebaseAuth.currentUser)
} else {
// If sign in fails, display a message to the user.// unable to retrieve details of the user
Log.w(
TAG,
"signInWithCredential:failure:: FirebaseAuthentication failed even though accesstoken present",
it.exception
)
Toast.makeText(
baseContext, "Authentication failed.",
Toast.LENGTH_SHORT
).show()
}
}
If I do a fresh install of the app and perform a sign in it works properly provided that the internet is turned on while I try to login into the app
First check for internet connection before executing the above code.
I figured out the issue. I added an active internet condition before performing a login that fixed sign-in problem. check the internet available on the device then only perform the login
I did face another issue that is addOnCompleteListener never gets called because I was waiting on the main thread instead I used executor to perform the task on a background thread

Reset password inside the app using flutter

The question is about Firebase authentication :
Do you know how to reset password "inside" the app ? I know how to reset it through a link using this function :
firebaseAuth.sendPasswordResetEmail(email: email)
But I do not find a way to do it inside the app with flutter.
Thanks
Here is a snipped for updating user password.
user.updatePassword(newPassword).then(function() {
// Update successful.
}).catch(function(error) {
// An error happened.
});
for more info, read https://firebase.google.com/docs/auth/web/manage-users

How to do logout with Meteor js to a user logged with facebook?

In my mobile app made with the meteor js, when the user login with facebook and try log out, when the user access the app again he has logged automatically. By the way, the user was not logged out.
This is my log out code:
Meteor.logout(function () {
// redirect to login page
});
Try removing the meteorlogintoken from local storage. You may also need to remove the resume token from a user in the users collection (if one exists).
Can’t say for sure as I don’t use Facebook with meteor but the above works for a standard meteor user
To further help diagnose the problem, you can test if the call to Meteor.logout returned an Error in the callback, something like:
Meteor.logout(function(err) {
if(err) {
console.error(err);
} else {
// Re-direct to login page
}
);
See: https://docs.meteor.com/api/accounts.html#Meteor-logout

Identify users / generate token for Ionic.io Push

I have an inherited Ionic framework app that is using Ionic.io
The app authorises against our API, and is given an API token to use in future requests.
I'm trying to work on push notifications - I've set up ionic push, and can trigger push notifications out to all users with no problems.
I'd like the ability to target specific users / devices to send notifications, and I understand that to do this, I have to register the device to generate a token.
Within my $ionicPlatform.ready function, I have:
$ionicPush.register().then(function(t) {
return $ionicPush.saveToken(t);
}).then(function(t) {
console.log('Token saved:', t.token);
});
This however does not seem to be returning a token, and calling
console.log($ionicPush);
Shows that the token is not set.
Any ideas here? What am I missing?
So after digging though some documentation, I found that the issue was linked with the ionic user.
In the main run function, I fire off a
if ($ionicAuth.isAuthenticated()) {
If this fails, I try a login of a user, and a register of the user if appropriate. (user is already logged in using a custom auth token against our api)
Before I attempt to register the token, I then have to reload the user in order to have the app save off and push back up to ionic.io.
$ionicUser.load().then(function() {
$ionicPush.register().then(function(t) {
console.log('Token sent:', t.token);
return $ionicPush.saveToken(t);
}).then(function(t) {
console.log('Token saved:', t.token);
});
});

Signin with Twitter stopped working suddenly

I have a web application which uses Twitter's OAUTH to login users. I am using Twitter4J version 2.1.11
This application has been working flawlessly and stopped working very recently, possibly in the past couple of weeks.
public static void authWithTwitter() {
try {
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
RequestToken requestToken = twitter.getOAuthRequestToken(getTwitterCallbackUrl());
// save requestToken for retreival after user logs in
// code not shown for brevity
redirect(requestToken.getAuthenticationURL());
} catch(Exception e) {
cLogger.error("Could not perform pre twitter login steps", e);
}
}
This code would (till the app was working) redirect the user to Twitter's login page, which upon successful authentication, would call the callback url.
However, recently, this has stopped working and I get the following Exception.
401:Authentication credentials (http://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
Failed to validate oauth signature and token
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=8dda30a8 or
http://www.google.co.jp/search?q=68161d96
TwitterException{exceptionCode=[8dda30a8-68161d96], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.11}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:199)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:75)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:112)
at twitter4j.http.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:148)
at twitter4j.TwitterOAuthSupportBaseImpl.getOAuthRequestToken(TwitterOAuthSupportBaseImpl.java:88)
at twitter4j.Twitter.getOAuthRequestToken(Twitter.java:58)
I did some searching and verified that I have the callback url set properly in my app's settings in dev.Twitter.com
I have not yet re-generated the key and consumer secret, but that would be the next step if I cannot get it to work.
Does anyone have a clue, why this would stop working ?
Make sure the servers clock is set correctly. If it is more than a few minutes off from Twitter's requests will fail.