Cannot enable email/password authentication provider - javascript

I am enabling email/password sign in method in firebase menu.The code for creating a new user and also to login are given below:
$scope.chatRef = new Firebase("https://project-497516355415797631.firebaseio.com");
$scope.login = function(){
$scope.chatRef.authWithPassword({
email : "debojyoti1#gmail.com",
password : "123456"
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
}
$scope.createUser = function(){
$scope.chatRef.createUser({
email : "bobtony#firebase.com",
password : "correcthorsebatterystaple"
}, function(error, userData) {
if (error) {
console.log("Error creating user:", error);
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
}
Still the error Error: The specified authentication provider is not enabled for this Firebase. is showing.What i am doing wrong?Thank you for your time.

You are using the old SDK for your project. the "new Firebase("etc...")" is for the Firebase Legacy Version not the Firebase 3.0 version you should use this documentation
https://firebase.google.com/docs/web/setup

Related

Node JS and Angular Email Verification: Anyway to send html in a response?

To start off, I do want to clarify that I know how to use APi's created in NodeJS in Angular. The problem I have is a little tricky.
I have a function that verifies the email used in registering:
exports.confirmEmail = function (req, res) {
ConfirmToken.findOne({
token: req.params.token
}, function (err, token) {
if (err) {
return res.status(500).send({
message: "Internal Server Error " + err
})
}
// token is not found into database i.e. token may have expired
if (!token) {
return res.status(400).send({
message: 'Your verification link may have expired. Please click on resend for verify your Email.'
});
}
// if token is found then check valid user
else {
Account.findOne({
_id: token._accountId,
email: req.params.email
}, function (err, user) {
if (err) {
return res.status(500).send({
message: "Internal Server Error " + err
})
}
// User does not exist
if (!user) {
return res.status(401).send({
message: 'The account does not exist'
});
}
// user is already verified
else if (user.isVerified) {
return res.status(200).send('User has been already verified. Please Login');
}
// verify user
else {
// change isVerified to true
user.isVerified = true;
user.save(function (err) {
// error occur
if (err) {
return res.status(500).send({
message: err.message
});
}
// account successfully verified
else {
return res.status(200).send('Your account has been successfully verified');
}
});
}
});
}
})
}
This is the response I get when I register an account
Now my question is: is there a way to pass in html code or have it show in a custom Angular component instead of displaying as simple plain text on the web browser as such
Your service should send a isVerified status back to the client. You are sending only a string at the moment
return res.status(200).send('Your account has been successfully verified');
based on this status, let's call it, isVerified your angular app would render a isVerfiedComponent.ts or notVerifiedComponent.ts

How to convert an anonymous account to a permanent account

can someone help me how to convert an anonymous account (signInAnonymouslyAndRetrieveData) to a permanent account ?
I have tried this:
firebase.auth().currentUser.linkAndRetrieveDataWithCredential(credential).then(function(usercred) {
var user = usercred.user;
console.log("Anonymous account successfully upgraded", user);
}, function(error) {
console.log("Error upgrading anonymous account", error);
});
but i'm getting an
cannot read property "linkAndRetrieveDataWithCredential" of null
error.
firebase.auth().currentUser will be null if there's no currently signed in user.
Ensure your anonymous user is still signed in then as in your example above you can then upgrade your user using linkAndRetrieveDataWithCredential
const credential = firebase.auth.EmailAuthProvider.credential(email, password);
const currentUser = firebase.auth().currentUser;
if (currentUser) {
currentUser.linkAndRetrieveDataWithCredential(credential).then((userCredential) => {
const user = userCredential.user;
console.log("Account linking success", user);
}, (error) => {
console.log("Account linking error", error);
});
}
References:
Official Firebase guide to account linking:
https://firebase.google.com/docs/auth/web/account-linking
React Native Firebase reference doc:
https://rnfirebase.io/docs/v4.3.x/auth/reference/User#linkAndRetrieveDataWithCredential

React Native Firebase authentication error handling

How to set state ('this.setState({})') inside error handling function for Firebase auth?
its not working in React Native.
onSignUpPress() {
if (this.state.password !== this.state.passwordConfirmation ) {
return this.setState({errorMessage: 'Your passwords do not match'});
}
ref.createUser({
email : this.state.email,
password : this.state.password
}, function(error, authData) {
if (error) {
console.log(error);
// this.setState({errorMsg: error}) <-- Like this, it not work on React Native.
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
}
});
Try rewriting the function using es6 fat arrow syntax. One issue for sure in the above code is that this is not bound to the correct scope. Try writing the function like this:
onSignUpPress() {
if (this.state.password !== this.state.passwordConfirmation ) {
return this.setState({errorMessage: 'Your passwords do not match'});
}
ref.createUser({
email : this.state.email,
password : this.state.password
},(error, authData) => {
if (error) {
console.log(error);
this.setState({errorMsg: error})
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
}
})

AngularJS - Route to different view after Firebase login

Based on the authentication data from Firebase when logging in, I want to route to a certain view after the login was successful.
app.controller('PageCtrl', function ($scope, $location, $http ) {
$scope.logIn = function(){
var email = $('#login-email').val();
var password = $('#login-password').val();
myDataRef.authWithPassword({
email : email,
password : password
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
email = myDataRef.getAuth().password.email;
$('#userinfo').html(email);
$('#logoutButton').show();
}
});
$location.path('/form'); //route to form
}
}
By using $location.path('/form'); The view will change, but this happens before the login was determined to be successful or unsuccessful. How can I route to one view after the login was successful, and another view if the login was unsuccessful? I placed the $location.path('/form'); inside the if else error logic but it doesn't work.
What does the authWithPassword method look like?
It is probably returning a promise and you should use the .then success/error callback to enforce the flow you are looking for. Something like this should work.
ref.authWithPassword({
"email": "bobtony#firebase.com",
"password": "correcthorsebatterystaple"
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
$location.path("/loginFailedPathHere");
} else {
console.log("Authenticated successfully with payload:", authData);
$location.path("/form");
$scope.$apply()
}
});

Why do I get Can't find variable: GlobalStore in React Native ios Facebook login

I'm using the following module in my React Native app in order to login users with Facebook. https://github.com/facebook/react-native-fbsdk
I logged the following issue.
https://github.com/facebook/react-native-fbsdk/issues/58
I have the following in my view and I get the GlobalStore can't find error.
var FBSDKLogin = require('react-native-fbsdklogin');
//init facebook login
fbTouchHandler(event) {
FBSDKLoginManager.setLoginBehavior(GlobalStore.getItem('behavior', 'native'));
FBSDKLoginManager.logInWithReadPermissions([], (error, result) => {
if (error) {
alert('Error logging in.');
} else {
if (result.isCancelled) {
alert('Login cancelled.');
} else {
alert('Logged in.');
}
}
});
}

Categories