useraccounts:flow-routing

v1.12.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Flow Router add-on for User Accounts

User Accounts is a suite of packages for the Meteor.js platform. It provides highly customizable user accounts UI templates for many different front-end frameworks. At the moment it includes forms for sign in, sign up, forgot password, reset password, change password, enroll account, and link or remove of many 3rd party services.

This package is an optional add-on for integration with Flow Router and Blaze Layout.

Configuration

Before you configure routes for User Accounts with Flow Router, you will need to make sure you have set a few default configuration items.

Assuming you have a main layout that looks like this:

<template name="myLayout">
  
  <div class="nav">
    {{> Template.dynamic template=nav}}
  </div>
  
  <div class="content">
    {{> Template.dynamic template=main}}
  </div>

  <footer>
    {{> Template.dynamic template=footer}}
  </footer>
  
</template>

You would configure this package to use it like this:

1AccountsTemplates.configure({
2    defaultLayout: 'myLayout',
3    defaultLayoutRegions: {
4        nav: 'myNav',
5        footer: 'myFooter'
6    },
7    defaultContentRegion: 'main'
8});

If you don't have extra content regions (nav, footer, etc) you should pass an empty object to the config like this:

1AccountsTemplates.configure({
2    defaultLayout: 'myLayout',
3    defaultLayoutRegions: {},
4    defaultContentRegion: 'main'
5});

NOTE: The above configs must load BEFORE your AccountsTemplates routes are defined (next section).

Routes

There are no routes provided by default, but you can easily configure routes for sign in, sign up, forgot password, reset password, change password, enroll account using AccountsTemplates.configureRoute.

The simplest way is to make the call passing in only a route code (available route codes are: signIn, signUp, changePwd, forgotPwd, resetPwd, enrollAccount).

This will set up the sign in route with a full-page form:

1AccountsTemplates.configureRoute('signIn');

You can also pass in more options to adapt it to your needs with:

1AccountsTemplates.configureRoute(route_code, options);

The following is a complete example of a custom route configuration:

1AccountsTemplates.configureRoute('signIn', {
2    name: 'signin',
3    path: '/login',
4    template: 'myLogin',
5    layoutTemplate: 'myLayout',
6    layoutRegions: {
7      nav: 'myNav',
8      footer: 'myFooter'
9    },
10    contentRegion: 'main'
11});

All options are passed to FlowRouter.route() which then creates a new custom route (see the official Flow Router documentation here for more details). All the above fields are optional and fall back to default values in case you don't provide them.

Content Protection

If you want to protect a route by making sure a user is signed in, you can add the AccountsTemplates.ensureSignedIn check in your route's enter triggers like this:

1FlowRouter.route('/private', {
2  triggersEnter: [AccountsTemplates.ensureSignedIn],
3  action: function() {
4    BlazeLayout.render(...)
5  }
6});

If the user isn't signed in, they will be redirected to your sign in route and then redirected back to the original route after they have successfully signed in.

Or if you want to protect ALL routes in your app:

1FlowRouter.triggers.enter([AccountsTemplates.ensureSignedIn]);