0

When a person signs up (accounts entry) it takes them to a page called "dashboard". I want it so that after they sign-up if it is the first time (for that account) that they are seeing the page it will show some sort of welcome message. Is this possible?

Thanks.

Update: I tried this:

Accounts.onCreateUser(function(options, user) {
    console.log('New account created!');
});  

But it gave:

Exception while invoking method 'entryCreateUser' Error: insert requires an argument

I am using Accounts Entry. Is there any fix for this?

2 Answers2

1

Without knowing more about your app it's difficult to advise on the best way for you to do this. But here are three possible approaches.

  • If you are creating your own signup/login events, just route to a 'welcome' route/template on signup event, and 'dashboard route/template on login.

  • If you are wanting to use default accounts-ui, you can use the Accounts.onCreateUser hook server side to add {'isNewUser' : true} to the user account document. Then check for this property client side to decide what template to display.

  • Or you can try wrapping Accounts.createUser to include the extra logic you require client side to go to your welcome route/template rather than the dashboard.

Community
  • 1
  • 1
JeremyK
  • 3,240
  • 1
  • 11
  • 24
0

The simplest way is to set a session variable then use a helper in your template to key off of that:

In your new account code:

Session.set('isNewUser',true);
Router.go('dashboard')

HTML:

<template name='dashboard'>
{{#if newUser}}Welcome!!{{/if}
... rest of your template ...
</template>

js:

Template.dashboard.helpers({
  newUser: function(){
    return Session.get('isNewUser');
  }
});

You'll also need code to later either delete that Session variable or set it to false.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
  • I am using Accounts.entry, so do you know how I would add the session.set part? –  Oct 06 '15 at 22:20
  • Ah, I didn't realize you were using such a package! From reading the docs it's not clear how to get a callback that a new user has just been created. Especially with 3rd party services that may or may not require email validation. You may be better off returning your user's `createdAt` date and then showing the new user message for a short time. `onCreateUser()` is only available on the server and you need this on the client. – Michel Floyd Oct 06 '15 at 22:56