optional setting in angularfire authwithpassword - firebase

I am using AngularFire $authWithPassword(credentials[, options]) for login. I assume [options] is "remember" with value of default, sessionOnly, none, as described here.
I tried all 3, I can not see any difference in my mobile app. I logged in my app, then kill/close my app, restart it. All 3 options let my app persist/remember username and password and logged in. Should at least None forget authentication data?
This is the code I use for authentication:
var _remember="default";
if (!$scope.isAutoLogin){ _
remember="none";
//"sessionOnly";
};
auth.$authWithPassword({ email: user.email, password: user.password, remember:_remember })
.then(function (authData) {
console.log("Logged in as:" + authData.uid);
}).catch(function (error) {

If I see it correctly it is just a matter of syntax, your login should be like this:
auth.$authWithPassword({
email : user.email,
password : user.password
}, {
remember: "sessionOnly"
});

Related

Not able to login - User has no password set

I don't want to use accounts-ui or accounts-ui-unstyled, only accounts-password, thus I decided to use the Accounts and Meteor methods.
I create a user with the following code (client):
Accounts.createUser({
email: email,
emails: [{address: email, verified: false}],
password: password,
profile: {
name: name
}
}, function(err) { ... });
which seems to be working fine, however when I try to create do a login with this code (client):
Meteor.loginWithPassword(username, password, function(err){
console.error(err);
});
Doesn't matter if the password is correct or not it always replies: Error: User has no password set [403].
Meteor version: 1.4.2.3

Not able to maintain user authentication session firebase

I am using email & password authentication to logging in user, from my firebase dashboard i have set session expiration time to 2 months . However when i am closing my app from background and then after reopening of app i am getting var user = ref.getAuth(); as null
Does firebase does't take care of this? How to keep user logged in for a long period of time?
Below is the piece of code i am using to login user. I am using react-native
ref.authWithPassword({
email : 'username',
password : 'password'
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
navigatorReference.push({name:'myFeed'})
console.log("Authenticated successfully with payload:", authData);
}
});
Firebase should take care of this. Double check your configuration in the Login & Auth tab in your App Dashboard to make sure you have that setup properly.
You could also try passing along the configuration like so...
ref.authWithPassword({
email : 'username',
password : 'password'
}, function(error, authData) { /* Your Code */ }, {
remember: "default"
});

No response from Jquery validation when creating Meteor account

Basically, I'm using Jquery validation package as a way to alert errors to users when creating and registering accounts on Meteor, since the boilerplate interface doesn't work in my case.
Anyway, when a user tries to sign up for an account, I get no response at all on client. The user is just created with no message or redirection like it's supposed to have.
Here is the particular code:
Template.createAccount.onRendered(function(){
var validator = $('.register').validate({
submitHandler: function(){
user = {
email: document.getElementById("email").value,
password: document.getElementById("password").value
};
Accounts.createUser({
email: user.email,
password: user.password,
function(error){
if(error){
if(error.reason == "Email already exists."){
validator.showErrors({
email: "The email belongs to a registered user."
});
}
} else{
console.log("Account successfully created.");
Router.go("starter");
}
}
});
}
});
})
I'm using the same code logic for account logins with the only exception being a different meteor accounts function (Meteor.loginWithPassword() for login and Accounts.createUser() for account creation).
No response at all, so it probably has to do something with the callback function, since the user account is created, but no message displayed on client.
You're including your callback as part of your options object when it should be a separate argument. It should look more like this:
Accounts.createUser({
email: user.email,
password: user.password
}, function(error){
if(error){
if(error.reason == "Email already exists."){
validator.showErrors({
email: "The email belongs to a registered user."
});
}
} else{
console.log("Account successfully created.");
Router.go("starter");
}
});

How would I use Accounts.createUser in Meteor once, at first load, and then persist

I have thought of somehow using session, but that doesn't make much sense to me with a user that I always want to exist, and not be created over and over.
My issue is after a page refresh I get an error saying user already exists, I would like to know how to create a permanent user once.
This is in my server code.
Accounts.createUser({
username: "admin",
password: "password"
});
Try this.
Meteor.startup(function () {
if (Meteor.users.find().count() === 0) {
Accounts.createUser({
username: 'admin',
email: 'admin#admin.com',
password: 'password'
});
console.log('created user');
}
});

New user can't change password in Meteor

When I add a new user, and open the link in the received verification email, the new user is logged in but can't change password. When I go to "Change password", I leave "current password" blank, type a password and click "Change password" and get the error "Match failed".
The user is created with a Meteor.call from the client to the following method:
Meteor.methods({
createUser: function(user) {
var userID = Accounts.createUser({
username: user.username,
email: user.email,
profile: {
firstName: user.firstName,
lastName: user.lastName,
}
});
Accounts.sendVerificationEmail(userID);
}
});
I have the following settings for Accounts.config and Accounts.ui.config:
Accounts.ui.config({
passwordSignupFields: 'USERNAME_AND_EMAIL'
})
Accounts.config({
forbidClientAccountCreation: false,
sendVerificationEmail: true
})
Thanks :-)
Why do you leave current password blank?
When creating an account you must specify a password otherwise it is considered null.
Try passing in password: "" when creating it if you intend to change it this way.
I would recommend you write a method to change it if you want them to enter a password after they have verified their account. Something like this:
Meteor.methods('changeMyPassword':function(newPassword) {
Accounts.setPassword(this.userId, newPassword);
});
The intention of the account verification email is that you create the account with a specified password and verify it after you've created the account.
Example of how to use Accounts.createUser

Resources