Accounts.createUser({
email: email,
password: password
}, function (err) {
console.log("inside createUser callback");
if (err) {
console.log("createUser failed", err);
return false;
}
console.log("callback inside createUser");
IonModal.close();
});
I am developing an ios app with Meteor (and Meteor Ionic), and I am stuck at a weird point. The callback for createUser only seems to be called when I test on my browser. In my iOS device, everything works except the callback. I don't see any error message.
Does anyone have an idea or have had a similar problem?
Related
I want to send verification email to users who just signed up. I have been looking for a solution for this and thought I found one, but it didn't work.
I checked out the Firebase Auth document and tried code on the page, but it also couldn't be the solution.
My code is below
The "try" actually runs when pressing the sign-up button and I can see it.
In the Firebase Auth console page, I can see the user just created but didn't get a verification email in the inbox.
const handleSignup = async (email, pswd) => {
try {
await createUserWithEmailAndPassword(auth, email, pswd);
setSignupEmail("");
setSignupPassword("");
setSignupPasswordAgain("");
signOut(auth);
sendEmailVerification(auth.currentUser);
alert("Check your email for a verification link.");
} catch (err) {
console.log(err);
}
};
You call sendEmailVerification() after having called signOut() so auth.currentUser is null when you pass it to sendEmailVerification(). You should see an error logged in the catch block.
Moreover, both sendEmailVerification() and signOut() methods are asynchronous and return Promises.
The following should do the trick (untested):
const handleSignup = async (email, pswd) => {
try {
await createUserWithEmailAndPassword(auth, email, pswd);
setSignupEmail("");
setSignupPassword("");
setSignupPasswordAgain("");
await sendEmailVerification(auth.currentUser);
await signOut(auth);
alert("Check your email for a verification link.");
} catch (err) {
console.log(err);
}
};
I'm using react-native-firebase for phone auth from firebase.
I'm following the documentation from https://rnfirebase.io/auth/phone-auth
// Handle the button press
async function signInWithPhoneNumber(phoneNumber) {
// Unreachable code. The Promise doesn't return anything here
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
setConfirm(confirmation);
}
async function confirmCode() {
try {
// confirm object is null, as signInWithPhoneNumber didn't return the promise.
await confirm.confirm(code);
} catch (error) {
console.log('Invalid code.');
}
}
This code fires the SMS, and if the same phone has it, the verification happens in the behind function onAuthStateChanged(user) ( still without returning a promise in the above call )
I've tried debugging the native code, and found that in ReactNativeAuthModule.java - onCodeSent() is having a verificationId
Why is my react promise still unresolved? Only then I can do the manual verification of OTP by confirm.confirm(code);
Any help is appreciated.
Update : here is the adb logcat
2021-07-23 16:56:10.769 6249-6330/com.zing D/Auth: signInWithPhoneNumber
2021-07-23 16:56:13.410 6249-6283/com.zing W/System: Ignoring header X-Firebase-Locale because its value was null.
async signIn() {
try {
let userCredential= await firebase.auth().signInWithEmailAndPassword(this.email, this.password)
console.log("user value is",userCredential)
this.$router.replace({name:'Sidebar'})
} catch (err) {
console.log("Invalid user", err);
}
},
},
};
When I use login without the await function it logs in, even on wrong credentials, and if I use the await function nothing happens and also it shows no errors.
When using the await function even on wrong credentials it's not showing an error, and also on correct credentials, it's not showing console.log value. What am I doing wrong here? why is it not checking DB for email and password!
You should dont use try catch here, make it simple like this. Beside you should not post information about firebase. It is sensitive infor.
firebase.auth().signInWithEmailAndPassword(this.email, this.password)
.then(function(firebaseUser) {
// Success
console.log("user value is", firebaseUser)
this.$router.replace({name:'Sidebar'})
})
.catch(function(error) {
// Error Handling
console.log("Invalid user", error);
});
I found the error. The form was not submitting the correct value at submission. Had to render the value outside the form and pass the values normally without form.
I'm having a bit of trouble catching errors from firebase authentication instances in flutter , I don't know what is wrong the code still throws exceptions even though i'm catching the errors , In addition , I have no idea how to identify the exception type whether its a badly formatted email , email already in use , weak password , etc.... and there is no proper documentation for such thing
I have tried this:
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _email, password: _password)
.then((currentUser) => {
//Execute
}).catchError((onError)=>{
print(onError)
});
And tried a simple try-catch block and none of them catch the exception
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _email, password: _password)
.then((currentUser) => {
//Execute
}).catchError((onError)=>{
//Handle error i.e display notification or toast
});
This code actually works but the editor (Visual Studio code) itself is throwing exceptions and crashing the app , if you run the app from the device or emulator itself the issue will be solved
You need to import - import 'package:flutter/services.dart';
then try this code:
FirebaseAuth.instance
.createUserWithEmailAndPassword(email: _email, password: _password)
.catchError((onError) => print(onError.message))
.then((authResult) => {
//Execute
})
I am developing an application, with an feature of Google Login through Firebase. I am trying to login via Google with the help of an library, known as react-native-google-signin. It is well known library in the field of ReactNative for Google Login.
My problem is not with this library, but the problem is that while I am using react-native-google-signin library with firebase to login via google. Firebase User is not staying persistence, I mean to say that when I am opening app after close FirebaseUser is getting null. Below the code I am using to login via firebase,
GoogleSignin.signIn().then(data => {
const credentials = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then() => {
return firebase.auth().signInWithCredential(credentials);
}).catch(error => {
console.log('Error', error);
})
}).then(user => {
console.log('user', firebase.auth().currentUser);
}).catch(error => {
console.log('Error', error);
})
I also checked Firebase Docs, tried by using setPersistence() method but still I am getting null user after open app again.
You can try this
when you first time open your app you get user null, but after login one time then reopen your app and you will get previously logged in user in your console
async _setupGoogleSignin() {
try {
await GoogleSignin.hasPlayServices({ autoResolve: true });
await GoogleSignin.configure({
webClientId: 'YOUR WEBCLIENTID',
offlineAccess: false
});
const user = await GoogleSignin.currentUserAsync();
console.log("user",user); // HERE YOU GET LOGGED IN USER IN YOUR CONSOLE FIRST TIME IT WILL BE NULL BUT AFTER YOU GET PREVIOUSLY LOGGED IN USER
this.setState({user});
}
catch(err) {
console.log("Play services error", err.code, err.message);
}}
then
_signIn() {
GoogleSignin.signIn()
.then((user) => {
console.log(user);
this.setState({user: user});
const credential = firebase.auth.GoogleAuthProvider.credential(user.idToken, user.accessToken);
// console.log(credential);
return firebase.auth().signInAndRetrieveDataWithCredential(credential);
})
.catch((err) => {
console.log('WRONG SIGNIN', err);
})
.done();}
it is worked for me...
hope it will help you...