meteor - How to redirect New User to different page one time only? -
ok when app starts after first time sign want redirect user different page.
in server code have this
accounts.oncreateuser(function(options, user) { hooks.oncreateuser = function () { meteor.router.to('/newuser'); } });
but want users redirected page if have been on more once have in client code, defaults client, doing wrong?
hooks.onloggedin = function () { meteor.router.to('/new'); }
if want redirect signed user, set flag within user object denoting whether redirected:
hooks.onloggedin = function (){ if(!meteor.user()) return; if(!meteor.user().returning) { meteor.users.update(meteor.userid(), {$set: {returning: true}}); meteor.router.to('/new'); } }
make sure publish & subscribe returning
field of user collection!
if want similar functionality visitors, use cookies.
hooks.onloggedin = function (){ if(!cookie.get('returning')) { cookie.set('returning', true); meteor.router.to('/new'); } }
here's handy package that: https://atmosphere.meteor.com/package/cookies
Comments
Post a Comment