Coder Social home page Coder Social logo

stubailo / flow-routing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meteor-useraccounts/flow-routing

0.0 3.0 0.0 53 KB

Useraccounts packages add-on for integration with Flow Router and Blaze Layout.

Home Page: https://atmospherejs.com/useraccounts/flow-routing

License: MIT License

JavaScript 100.00%

flow-routing's Introduction

Meteor Icon

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 either Blaze Layout or React Layout.

Blaze Configuration

Firstly, please ensure that your app depends upon the Blaze Layout package.

Then, 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:

AccountsTemplates.configure({
    defaultLayoutType: 'blaze', // Optional, the default is 'blaze'
    defaultTemplate: 'myCustomFullPageAtForm',
    defaultLayout: 'myLayout',
    defaultLayoutRegions: {
        nav: 'myNav',
        footer: 'myFooter'
    },
    defaultContentRegion: 'main'
});

If you don't have extra content regions (nav, footer, etc) you should pass an empty object to defaultLayoutRegions key of the config.

AccountsTemplates.configure({
    defaultLayout: 'myLayout',
    defaultLayoutRegions: {},
    defaultContentRegion: 'main'
});

useraccounts:flow-routing uses the internal useraccounts fullPageAtForm is the built-in template useraccounts uses by default for its forms. You can override it on a per-route basis (see below) or replace it with defaultTemplate: field as above (templates specified in route config will still take precedence). Omit defaultTemplate (or set to an empty string) to use the fullPageAtForm template built-in to your useraccounts UI package (ex material).

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

React Configuration

Firstly, please ensure that your app depends upon the React Layout and the Blaze Layout packages. User Accounts currents only renders Blaze templates. In order to use User Accounts with React we rely on the Blaze To React package to render the User Accounts templates.

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 following and you have <Nav /> and <Footer /> as your default nav/footer components:

MainLayout = React.createClass({
  render() {
    return (
      <div>
        <header>
          {this.props.nav || <Nav />}
        </header>
        <main>
          {this.props.main}
        </main>
        <footer>
          {this.props.footer || <Footer />}
        </footer>
      </div>
    );
  }
});

You would then configure this package to use it like this:

AccountsTemplates.configure({
  defaultLayoutType: 'blaze-to-react',
  defaultTemplate: 'fullPageAtForm',  // default
  defaultLayout: MainLayout,
  defaultLayoutRegions: {
    nav: <Nav />,
    footer: <Footer />
  },
  defaultContentRegion: 'main'
});

If you don't have extra content regions (nav, footer, etc) you should pass an empty object to the defaultLayoutRegions key of the config.

AccountsTemplates.configure({
	defaultLayoutType: 'blaze-to-react',
  defaultTemplate: 'myCustomFullPageAtForm',
  defaultLayout: MainLayout,
  defaultLayoutRegions: {},
  defaultContentRegion: 'main'
});

useraccounts:flow-routing uses fullPageAtForm for the defaultTemplate option. fullPageAtForm is the built-in Blaze template that all UserAccounts themed packages (Bootstrap, Materialize, etc.) use for their forms. You can override it on a per-route basis (see below) or replace it as shown above (templates specified in a route config will still take precedence). Omit defaultTemplate (or set to an empty string) to use the fullPageAtForm template built-in to your useraccounts UI package (ex material).

Please note that this template must be a Blaze template. It will be rendered into your React layout using Blaze To React.

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 at /sign-in:

AccountsTemplates.configureRoute('signIn');

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

AccountsTemplates.configureRoute(route_code, options);

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

Blaze
// routes.js

AccountsTemplates.configureRoute('signIn', {
  layoutType: 'blaze',
  name: 'signin',
  path: '/login',
  template: 'myLogin',
  layoutTemplate: 'myLayout',
  layoutRegions: {
    nav: 'customNav',
    footer: 'customFooter'
  },
  contentRegion: 'main'
});
React
// routes.jsx

AccountsTemplates.configureRoute('signIn', {
  layoutType: 'blaze-to-react',
  name: 'signin',
  path: '/login',
  template: 'myLogin',
  layoutTemplate: CustomLayout,
  layoutRegions: {
    nav: <CustomNav />,
    footer: <CustomFooter />
  },
  contentRegion: 'main'
});

All options are passed to FlowRouter.route() which then creates a new custom route (see the official Flow Router documentation here for more details).

Default values for all fields are as follows:

Action route_code Route Name Route Path Template Redirect after Timeout
change password changePwd atChangePwd /change-password fullPageAtForm
enroll account enrollAccount atEnrollAccount /enroll-account fullPageAtForm X
forgot password forgotPwd atForgotPwd /forgot-password fullPageAtForm X
reset password resetPwd atResetPwd /reset-password fullPageAtForm X
sign in signIn atSignIn /sign-in fullPageAtForm
sign up signUp atSignUp /sign-up fullPageAtForm
verify email verifyEmail atVerifyEmail /verify-email fullPageAtForm X
resend verification email resendVerificationEmail atresendVerificationEmail /send-again fullPageAtForm

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:

FlowRouter.route('/private', {
  triggersEnter: [AccountsTemplates.ensureSignedIn],
  action: function() {
    BlazeLayout.render(...);
    // or
    ReactLayout.render(...);
  }
});

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:

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

flow-routing's People

Contributors

100ideas avatar brettle avatar jshimko avatar splendido avatar timothyarmes avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.