OnLogin hook account meteor loop

I am creating an application using Meteor. I want to create a new basket identifier (like a basket where I can store items) every time a user logs into my application. However, every time I open a new page in the application, a new basket identifier is created. Does this mean that the application is "registered" every time I click on a new page in the application? Here is my code:

Accounts.onLogin(function(user){ var newCartId = uuid.new() Meteor.users.update({_id: user.user._id}, {$set: {'profile.cartId': newCartId}}) console.log('just created a new Cart ID at ' + Date()); }); 
+7
javascript login meteor account hook
source share
1 answer

Yes it's true.

Each time you open a new page, you are not logged in. When the localStorage token authenticates you, just like a cookie does, you register automatically. This hook also starts when you log in automatically.

It is difficult to determine how the user logs on. Meteor Meteor onLogin fires with any type of login method.

You can configure when you want your hook to start:

 Accounts.onLogin(function(info) { if(info.methodName == "createUser") { console.log("This user logged in by signing up"); }else if(info.type == "password") { console.log("This user logged in by using his/her password"); }else if(info.type == "resume") { console.log("This user logged in using a localStorage token"); } }); 

Thus, you can make an event fire only when the user logs in using his password. Or even when they subscribe. You can use this to prevent your hook from starting if the user opens a new page that uses the localStorage token to register.

+10
source share

All Articles