Display form fields based on user type with Meteor Useraccount package

38 Views Asked by At

Could anyone help me to figure out how to get around this please?

Here is the scenario: Assume there are three types of user namely student, teacher, and parent that I want to save in my collection using useraccounts package.

Problem

In my AccountsTemplates.addField({}), I'd like to configure it in such way that signup form is displaying 3 fields for student, four for teacher, and 5 fields for parent with the help of type: hidden property depending on who the user has chosen to be from these three below options.

Who Am I?

Parent

<a href="/new-account/parent">Parent</a>

student

Teacher

Attempted solutions

  1. I've tried with FlowRouter parameter and use the value provided by the user from the above options but the thing is AccountTemplate is suggested to be place in /lib whereby it's can be accessed both by the client and server but the problem is FlowRouter.getParam() doesn't work on server side.
  2. With pub/sub, in account-config.js I wrote this

    if(Meteor.isServer){ Meteor.publish('getParam', function(param){ console.log(param) })}else if(Meteor.isClient){ console.log(FlowRouter.getParam('user-type') }

And in routes.js

FlowRouter.route('/new-account/:user-type', { 
    action(){
     Meteor.subscribe('getParam', FlowRouter.getParam('user-type');
      // because here  .getParam can be accessed.
 }
}

It's just worked fine and reactive on server side but on client side, undefined

Thanks.

Regards,

0

There are 0 best solutions below