can't catch firebase signInWithEmailAndPassword error - javascript

I am creating authentication with react and firebase.
Everything works fine when login details are correct but when email or password is wrong I can't catch error
I was following 'Web Dev Simplified' with this one(but I used vite to create project and newer version of firebase) but mine is not working as expected
async function handleSubmit(e) {
e.preventDefault()
try {
await signIn(emailRef.current.value, passRef.current.value)
} catch(error) {
console.log('error:', error)
}
}
function signIn(email, password){
auth.signInWithEmailAndPassword(email, password)
}
I got followings errors in console
index.ts:118 POST https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=A...
and
assert.ts:136 Uncaught (in promise) FirebaseError: Firebase: The password is invalid or the user does not have a password. (auth/wrong-password).
at createErrorInternal (assert.ts:136:55)
at _fail (assert.ts:65:9)
at _performFetchWithErrorHandling (index.ts:177:9)
at async _performSignInRequest (index.ts:195:27)
at async _signInWithCredential (credential.ts:37:20)
any ideas?

Related

Error: [auth/operation-not-allowed] in authetication using firebase in react native

Error: [auth/operation-not-allowed] The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section. [ The identity provider configuration is not found. ]
Having this error even if I have enabled the google sign-in provider in my firebase app. I have rechecked my SHA1 keys, but I still, have this error. I am trying to achieve authentication using firebase in react native android application.
Library used: #react-native-firebase/auth
Apparently, the same app(code) was working until I restarted the server. Please help! I have gone through relevant posts on all media but still haven't got the solution.
async function onGoogleButtonPress() {
// Get the users ID token
const {idToken} = await GoogleSignin.signIn();
// Create a Google credential with the token
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
console.log(`CREDS ${googleCredential}`);
console.log(googleCredential);
try {
auth().signInWithCredential(googleCredential);
} catch (err) {
console.log(`Error 123 ${err}`);
}
// Sign-in the user with the credential
return;
}
onGoogleButtonPress() is the function I am using to sign in using google.

Suppressing Firebase error logging on failed signInWithEmailAndPassword

I am attempting to implement login functionality using Firebase auth, in NextJS. Calling the function with invalid login details logs an error to the console, despite the empty catch statement in the handler for the login function. How do I suppress Firebase from logging this error to the console?
Login function handler:
const signinWithEmail = async (email, password) => {
setLoading(true);
signInWithEmailAndPassword(auth, email, password)
.then((response) => {
handleUser(response.user);
Router.push("/");
})
.catch((error) => {
// Do nothing
});
};
Error in console (blurred due to exposed API key):
Those network error logs are shown by the browser when the request returns an error. The catch block in code still works as intended. This can be disabled but by users themselves. Checkout: Suppress Chrome 'Failed to load resource' messages in console
The API key visible in the request is meant to be public and that's not an issue. Checkout:
Is it safe to expose Firebase apiKey to the public?

Can't login with Meteor function loginWithPassword, Unrecognized options for login request [400] error

I'm working on React + Meteor application and can't login using accounts-password package via loginWithPassword function.
The official API says that Unrecognized options for login request [400] error pops up when your user or password is undefined (or, i guess, just do not match the API), but i've checked the arguments and everything seems correct. username and password are strings. Meteor has ability to operate with user object, but this is not working too.
Here's the sample of my code.
const submit = useCallback(
(values) => {
const { email, password } = values;
const callback = (err) => {
if (err) {
console.log(err);
notifyError();
return;
}
login();
history.replace(from);
};
Meteor.loginWithPassword(email, password, callback);
},
[from, history, login, notifyError]
);
Any help appreciated.
It looks like that particular error can occur when there are no login handlers registered.
Have you added the accounts-password package ?
meteor add accounts-password

VueJS & Firebase - How to validate someone's password

I have a web form built with VueJS that allows authenticated users to change their passwords. The backend is using Firebase, and I'm trying to validate the user's current password prior to calling the password-change API.
My code looks like this:
rules: {
...
isPreviousPassword: v => {
var credentials = await firebase.auth().currentUser
.reauthenticateWithCredential(
firebase.auth.EmailAuthProvider.credential(
firebase.auth().currentUser.email,
v)
)
return credentials || 'Your password is incorrect'
}
}
Babel refuses the code above and returns the following error:
Syntax Error: await is a reserved word
I haven't found any ways to get over this error, and none of the code snippets I found online, which are reported to work, are being blocked by Babel, which throws the same error message as above.
What's the best way to solve this?
Try to add async to your function:
isPreviousPassword: async (v) => {
var credentials = await firebase.auth().currentUser
.reauthenticateWithCredential(
firebase.auth.EmailAuthProvider.credential(
firebase.auth().currentUser.email,
v)
)
return credentials || 'Your password is incorrect'
}

Firebase Anonymous Authentication issue

I am using Firebase Simple Login (version 1.6.1) to authenticate anonymously. I start with,
var livepolling_ref = new Firebase(FIREBASE_URL);
var auth = new FirebaseSimpleLogin(livepolling_ref, function(error, user) {
if (error) {
console.log('An error!');
} else if (user) {
//Boot the App and save the user.id
//I'm able to reach this point in the code using the debugger
}
});
auth.login('anonymous');
I have checked that user has a uid and a FirebaseAuthToken in the callback, and I save the user id. So it seems that I am logged in.
However, I have the following security on my entire Firebase repo.
".write": "auth != null"
When I check the Chrome Console, it tells me "permission denied."
I realized my mistake--I was referencing the wrong Firebase Repo. Sorry for the confusion!

Categories

Resources