MeteorJS Logging in User with User Object - meteor

I have user object from database in my Blaze Helper file:
Object {_id: "mFx4Fa8aPpoFweziq", services: Object, emails: Array[1], profile: Object}
I want to login this user using above object which contains email as well as hash password.
I have following accounts packages: accounts-password accounts-ui

You can login with the loginToken saved inside services.resume.loginTokens
Get the token from the array of tokens and use the following method
Meteor.loginWithToken(token, callback)
check here
that is how meteor reads the value from localstorage and automatically log you in when you re-open the website
If you don't have access token you can create one, check this

Related

Firebase auth customClaims not exists for user created with help of createCustomToken()

I want to store some secret data in user' customClaims. I create a token on server with:
var customToken = createCustomToken(uniqueId, {mySecretData:"VerySecretData"}),
sending it to my app , logging user in with signInWithCustomToken(customToken), and it works fine,
BUT, when i am fetching user later on server by calling admin's getUser(uniqueId) and trying to see its customClaims there is nothing, undefined.
The interesting thing is that i do see this secret data in callable function context' auth property' token object.
Question: why developerClaims are not user' customClaims ?
Reference: https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createcustomtoken
Claims added via createCustomToken() only exist in the Auth token issued by the Firebase Auth. They are not stored anywhere beyond that, and getUser() response will not include them. You should use the setCustomUserClaims() to get the behavior you've indicated.

FIrebase auth: check if user exist before create new one with signInWithPopup()

I want to add the ability for already registered users to log in using Facebook. I'm using signInWithPopup method with FacebookAuthProvider for this. But when user with the same email does not exist, Firebase creating the new user - what I don't need.
Can I somehow cancel the creation of a new user after successful login via Facebook, if I do not have a user with the same Email?
signInWithPopup will return a UserCredential object if everything went right. If you want, you can check the _tokenResponse property of the object, which itself is another object containing a property called isNewUser. As you might have guessed this property returns whether the currently signed-in user is a new user or not. If it's a new user you can delete the user via firebase.auth.currentUser().delete(), otherwise it's not a new user and you can handle it accordingly.
The best solution is to delete the newly created user like so:
var user = firebase.auth().currentUser;
user.delete().catch(function(error) {
console.log(error);
});
You can check this out: https://firebase.google.com/docs/auth/web/manage-users#delete_a_user

How to reauthenticate a user using nativescript and firebase

I'm developing an app using nativescript and firebase.
On the firebase.init method i use
persist : true
When i close the app and reopen it the init method gets the current user on the
onAuthStateChanged callback
But still not understand the whole process.
My question is :
Is the init method anought for user reauthentication ??
Or should i do something more??
save the email and password on local storage and when the app startup call in the ngoninit the login function with the email and password from local storage
if the data exist the login process will finish successfully if not used will move to the login page.

Meteor.js / React.js App - how to add another user while you're logged in

How do I add another user while I'm logged in in a Meteor application. I want to give to an admin an ability to create users himself without logging out.
For login system I use accounts-password#1.3.2
If I use Accounts.createUser(user, function (e) { ... } then it logs out my admin and after a page refresh it logs in with a new user instead.
SOLVED:
Thanks to below answers I created
Meteor.call('addingUser.insert', user);
on the front where user is an object of values and then
'addEmployee.insert'(user) {
Accounts.createUser(user);
}
on the back end and a user was added successfully with an appropriately generated bcrypt password.
If you create the user in a Meteor method (ie on the server, not the client), it will create the user in the backend, and not change the login status of the current user.
Create a method that handles user creation (you could use accounts-password for this) in the server. Call that method in the client.
for more info about accounts-password refer to this: http://docs.meteor.com/api/passwords.html#Accounts-createUser
Let me know if this works or not. Thanks!

created user account does not show in browser console

This Meteor app which uses accounts-password package and a custom login form with autopublish package removed, creates a user account using Accounts.createUser on the server.
Even though a user has been created and verified db.users.find({}).pretty() in the meteor mongo terminal, this command Meteor.users.find().fetch() in the browser console gives an empty array []
edit
Meteor.user() in the browser console returns null
edit 2
The steps to fire the Accouts.createUser is as follows:
A template button event calls a method A, which on the server it stores the username and password in a global object, then calls a method B which then calls a server side function which calls Acounts.createUser using the username and password in the global object.
server.js
Meteor.publish('users', function () {
if (this.userId) {
return Meteor.users.find({_id: this.userId});
}
});
client.js
Meteor.subscribe('users');
Is this normal? and if so, how does meteor know which browser "session" belongs to which client? Thanks
Have a look at the docs for Accounts.createUser:
On the client, this function logs in as the newly created user on successful completion. On the server, it returns the newly created user id.
So if you only create the user from the server, the user won't be automatically logged in. If the user isn't logged in, his/her user document won't be published.
You have two choices:
Call Accounts.createUser from the client.
Ask the user to login after the account is created on the server.

Resources