All Projects → studiointeract → Accounts Ui

studiointeract / Accounts Ui

Licence: mit
Accounts UI for React in Meteor 1.3+

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Accounts Ui

Loadable Components
The recommended Code Splitting library for React ✂️✨
Stars: ✭ 6,194 (+3044.16%)
Mutual labels:  ssr, react-router
Dva Starter
完美使用 dva react react-router,最好用的ssr脚手架,服务器渲染最佳实践
Stars: ✭ 60 (-69.54%)
Mutual labels:  ssr, react-router
Base
A starting point for Meteor apps.
Stars: ✭ 654 (+231.98%)
Mutual labels:  meteor, react-router
After.js
Next.js-like framework for server-rendered React apps built with React Router
Stars: ✭ 4,051 (+1956.35%)
Mutual labels:  ssr, react-router
Award
⚙基于react的服务端渲染框架
Stars: ✭ 91 (-53.81%)
Mutual labels:  ssr, react-router
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+124.87%)
Mutual labels:  ssr, react-router
React 5ddm
5d动漫,使用React,服务端渲染,接口(不开源)来自赞片CMS。仅供参考,交流群:14646823 欢迎加入
Stars: ✭ 50 (-74.62%)
Mutual labels:  ssr, react-router
react-ssr
从零搭建一个react-ssr框架 解决页面js事件 样式同构 服务器客户端路由 数据注水脱水等问题
Stars: ✭ 42 (-78.68%)
Mutual labels:  react-router, ssr
React Redux Saucepan
A minimal and universal react redux starter project. With hot reloading, linting and server-side rendering
Stars: ✭ 86 (-56.35%)
Mutual labels:  ssr, react-router
Preact Redux Isomorphic
preact-redux-isomorphic PWA SPA SSR best practices and libraries in under 80kB page size (for live demo click the link below)
Stars: ✭ 85 (-56.85%)
Mutual labels:  ssr, react-router
React Lego
React-lego : incrementally add more cool stuff to your react app
Stars: ✭ 417 (+111.68%)
Mutual labels:  ssr, react-router
Nostalgie
Nostalgie is an opinionated, full-stack, runtime-agnostic framework for building web apps and web pages using react.
Stars: ✭ 130 (-34.01%)
Mutual labels:  ssr, react-router
Ice
🚀 The Progressive App Framework Based On React(基于 React 的渐进式应用框架)
Stars: ✭ 16,961 (+8509.64%)
Mutual labels:  ssr, react-router
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+185.79%)
Mutual labels:  meteor, ssr
react16-seed-with-apollo-graphql-scss-router4-ssr-tests-eslint-prettier-docker-webpack3-hot
Seed to create your own project using React with Apollo GraphQL client
Stars: ✭ 19 (-90.36%)
Mutual labels:  react-router, ssr
Vue Meteor
🌠 Vue first-class integration in Meteor
Stars: ✭ 893 (+353.3%)
Mutual labels:  meteor, ssr
async-react-router
Client side react router with async. It like next.js!
Stars: ✭ 21 (-89.34%)
Mutual labels:  react-router, ssr
elegant-react-ssr
Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk boilerplate, without ejecting CRA
Stars: ✭ 16 (-91.88%)
Mutual labels:  react-router, ssr
React Router Nextjs Like Data Fetching
Demonstrating React Router 4's SSR awesomeness
Stars: ✭ 84 (-57.36%)
Mutual labels:  ssr, react-router
Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (-41.12%)
Mutual labels:  ssr, react-router

React Accounts UI

Current version 1.3.0

Features

  1. Easy to use, mixing the ideas of useraccounts configuration and accounts-ui that everyone already knows and loves.
  2. Components are everywhere, and extensible by replacing them on Accounts.ui.
  3. Basic routing included, redirections when the user clicks a link in an email or when signing in or out.
  4. Unstyled is the default, no CSS included.
  5. No password sign up and sign in are included.
  6. Extra fields is now supported.
  7. Extending to make your own custom form, for your app, or as a package, all components can be extended and customized.
  8. States API makes it possible to use the form on different routes, say you want the login on one route and signup on another, just set the inital state and the links (either globally or per component by using the props).
  9. React Router is fully supported, see the example how to use with React Router.
  10. FlowRouter is fully supported, see the example how to use with FlowRouter.
  11. Server Side Rendering is easily setup, see how it's done with FlowRouter (SSR). An example for React Router using react-router-ssr coming shortly.

Styling

This package does not by standard come with any styling, you can easily extend and make your own, here are a couple versions we've made for the typical use case:

Installation

meteor add std:accounts-ui

Configuration

We support the standard configuration in the account-ui package. But have extended with some new options.

Accounts.ui.config(options)

import { Accounts } from 'meteor/std:accounts-ui'

Configure the behavior of <Accounts.ui.LoginForm />

Example configuration:

Accounts.config({
  sendVerificationEmail: true,
  forbidClientAccountCreation: false
});

Accounts.ui.config({
  passwordSignupFields: 'EMAIL_ONLY',
  loginPath: '/login',
  signUpPath: '/signup',
  resetPasswordPath: '/reset-password',
  profilePath: '/profile',
  onSignedInHook: () => FlowRouter.go('/general'),
  onSignedOutHook: () => FlowRouter.go('/login'),
  minimumPasswordLength: 6
});

Version 1.2 also supports passing hooks through props to the component.

import { Accounts } from 'meteor/std:accounts-ui';

<Accounts.ui.LoginForm
  onSignedInHook={ () => console.log('user signed in') }
/>

Options:

  • requestPermissions    Object
    Which permissions to request from the user for each external service.

  • requestOfflineToken    Object
    To ask the user for permission to act on their behalf when offline, map the relevant external service to true. Currently only supported with Google. See Meteor.loginWithExternalService for more details.

  • forceApprovalPrompt    Boolean
    If true, forces the user to approve the app's permissions, even if previously approved. Currently only supported with Google.

  • passwordSignupFields    String
    Which fields to display in the user creation form. One of 'USERNAME_AND_EMAIL', 'USERNAME_AND_OPTIONAL_EMAIL', 'USERNAME_ONLY', 'EMAIL_ONLY', 'USERNAME_AND_EMAIL_NO_PASSWORD', 'EMAIL_ONLY_NO_PASSWORD' (default).

  • requireEmailVerification    Boolean
    Set if the login without password should check if the user is verified before sending any login emails. Default is false.

  • minimumPasswordLength    Number
    Set the minimum number of password length for your application. Default is 7.

  • homeRoutePath    String
    Set the path to where you would like the user to be redirected after a successful login or sign out.

  • loginPath    String
    Change the default path a user should be redirected to after a clicking a link in a mail provided to them from the accounts system, it could be a mail set to them when they have reset their password, verifying their email if the setting for sendVerificationEmail is turned on (read more on accounts configuration ). Can also be set as a property to the LoginForm, for i18n routes or other customization.

  • signUpPath    String
    Set the path to where you would like the sign up links to link to rather than changing the state on the current page. Can also be set as a property to the LoginForm, for i18n routes or other customization.

  • resetPasswordPath    String
    Set the path to where you would like the link to reset password to go to rather than changing the state on the current page. Can also be set as a property to the LoginForm, for i18n routes or other customization.

  • profilePath    String
    Set the path to where you would like the link to the profile to go to rather than changing the state on the current page. Can also be set as a property to the LoginForm, for i18n routes or other customization.

  • changePasswordPath    String
    Set the path to where you would like the link to change password to go to rather than changing the state on the current page. Can also be set as a property to the LoginForm, for i18n routes or other customization.

  • onSubmitHook    function(error, state)
    Called when the LoginForm is being submitted: allows for custom actions to be taken on form submission. error contains possible errors occurred during the submission process, state specifies the LoginForm internal state from which the submission was triggered. A nice use case might be closing the modal or side-menu or dropdown showing LoginForm. You can get all the possible states by import STATES from this package.

  • onPreSignUpHook    function(options)
    Called just before submitting the LoginForm for sign-up: allows for custom actions on the data being submitted. A nice use could be extending the user profile object accessing options.profile. to be taken on form submission. The plain text password is also provided for any reasonable use. If you return a promise, the submission will wait until you resolve it.

  • onPostSignUpHook    func(options, user)
    Called client side, just after a successful user account creation, post submitting the form for sign-up: allows for custom actions on the data being submitted after we are sure a new user was successfully created.

  • onResetPasswordHook    function()
    Change the default redirect behavior when the user clicks the link to reset their email sent from the system, i.e. you want a custom path for the reset password form. Default is loginPath.

  • onEnrollAccountHook    function()
    Change the default redirect behavior when the user clicks the link to enroll for an account sent from the system, i.e. you want a custom path for the enrollment form. Learn more about how to send enrollment emails. Default is loginPath.

  • onVerifyEmailHook    function()
    Change the default redirect behavior when the user clicks the link to verify their email sent from the system, i.e. you want a custom path after the user verifies their email or login with EMAIL_ONLY_NO_PASSWORD. Default is profilePath.

  • onSignedInHook    function()
    Change the default redirect behavior when the user successfully login to your application, i.e. you want a custom path for the reset password form. Default is profilePath.

  • onSignedOutHook    function()
    Change the default redirect behavior when the user signs out using the LoginForm, i.e. you want a custom path after the user signs out. Default is homeRoutePath.

  • emailPattern    new RegExp()
    Change how emails are validated on the client, i.e. require specific domain or pattern for an email. Default is new RegExp('[^@][email protected][^@.]{2,}.[^[email protected]]+').

No password required

This package provides a state that makes it possible to create and manage accounts without a password. The idea is simple, you always verify your email, so to login you enter your mail and the system emails you a link to login. The mail that is sent can be changed if needed, just how you alter the email templates in accounts-base.

This is the default setting for passwordSignupFields in the configuration.

Using React Accounts UI

Example setup (Meteor 1.3)

meteor add accounts-password
meteor add std:accounts-ui

import React from 'react';
import { Accounts } from 'meteor/std:accounts-ui';

Accounts.ui.config({
  passwordSignupFields: 'EMAIL_ONLY_NO_PASSWORD',
  loginPath: '/',
});

if (Meteor.isClient) {
  ReactDOM.render(<Accounts.ui.LoginForm />, document.body)
}

Example setup using React Router (Meteor 1.3)

Following the Application Structure from the Meteor Guide.

npm i --save react react-dom react-router
meteor add accounts-password
meteor add std:accounts-ui

import React from 'react';
import { render } from 'react-dom';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import { Accounts, STATES } from 'meteor/std:accounts-ui';

import { App } from '../../ui/layouts/app.jsx';
import { Index } from '../../ui/components/index.jsx';

import { Hello } from '../../ui/pages/hello.jsx';
import { Admin } from '../../ui/pages/admin.jsx';
import { NotFound } from '../../ui/pages/not-found.jsx';

Meteor.startup( () => {
  render(
    <Router history={ browserHistory }>
      <Route path="/" component={ App }>
        <IndexRoute component={ Index } />
        <Route path="/signin" component={() => <Accounts.ui.LoginForm />} />
        <Route path="/signup" component={() => <Accounts.ui.LoginForm formState={STATES.SIGN_UP} />} />
        <Route path="/hello/:name" component={ Hello } />
      </Route>
      <Route path="/admin" component={ App }>
        <IndexRoute component={ Admin } />
      </Route>
      <Route path="*" component={ NotFound } />
    </Router>,
    document.getElementById( 'react-root' )
  );
});

You can learn more about the remaining components here in the tutorial on React Router Basics by the Meteor Chef.

Example setup using FlowRouter (Meteor 1.3)

npm i --save react react-dom meteor add accounts-password
meteor add std:accounts-ui
meteor add kadira:flow-router-ssr

import React from 'react';
import { Accounts } from 'meteor/std:accounts-ui';
import { FlowRouter } from 'meteor/kadira:flow-router-ssr';

Accounts.ui.config({
  passwordSignupFields: 'EMAIL_ONLY_NO_PASSWORD',
  loginPath: '/login',
  onSignedInHook: () => FlowRouter.go('/general'),
  onSignedOutHook: () => FlowRouter.go('/')
});

FlowRouter.route("/login", {
  action(params) {
    mount(MainLayout, {
      content: <Accounts.ui.LoginForm />
    });
  }
});

Example setup using the STATES api.

You can define the inital state you want in your route for the component, as set the path where the links in the component link to, for example below we have one route for /login and one for /signup.

meteor add accounts-password
meteor add std:accounts-ui
meteor add softwarerero:accounts-t9n
meteor add kadira:flow-router-ssr

import React from 'react';
import { Accounts, STATES } from 'meteor/std:accounts-ui';
import { T9n } from 'meteor/softwarerero:accounts-t9n';

T9n.setLanguage('en');

Accounts.config({
  sendVerificationEmail: true,
  forbidClientAccountCreation: false
});

Accounts.ui.config({
  passwordSignupFields: 'USERNAME_AND_OPTIONAL_EMAIL',
  loginPath: '/login'
});

FlowRouter.route("/login", {
  action(params) {
    mount(MainLayout, {
      content: <Accounts.ui.LoginForm {...{
        signUpPath: '/signup'
      }} />
    });
  }
});

FlowRouter.route("/signup", {
  action(params) {
    mount(MainLayout, {
      content: <Accounts.ui.LoginForm {...{
        formState: STATES.SIGN_UP,
        loginPath: '/login'
      }} />
    });
  }
});

Create your own styled version

To you who are a package author, its easy to write extensions for std:accounts-ui by importing and export like the following example:

// package.js

Package.describe({
  name: 'author:accounts-bootstrap',
  version: '1.0.0',
  summary: 'Bootstrap – Accounts UI for React in Meteor 1.3',
  git: 'https://github.com/author/accounts-bootstrap',
  documentation: 'README.md'
});

Package.onUse(function(api) {
  api.versionsFrom('1.3');
  api.use('ecmascript');
  api.use('std:accounts-ui');

  api.imply('session');

  api.mainModule('main.jsx');
});
// package.json

{
  "name": "accounts-bootstrap",
  "description": "Bootstrap – Accounts UI for React in Meteor 1.3",
  "repository": {
    "type": "git",
    "url": "https://github.com/author/accounts-bootstrap.git"
  },
  "keywords": [
    "react",
    "meteor",
    "accounts",
    "tracker"
  ],
  "author": "author",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/author/accounts-bootstrap/issues"
  },
  "homepage": "https://github.com/author/accounts-bootstrap",
  "dependencies": {
    "react": "^15.x",
    "react-dom": "^15.x",
    "tracker-component": "^1.3.13"
  }
}

To install the dependencies added in your package.json run:
npm i

// main.jsx

import React from 'react';
import PropTypes from 'prop-types';
import { Accounts, STATES } from 'meteor/std:accounts-ui';

/**
 * Form.propTypes = {
 *   fields: PropTypes.object.isRequired,
 *   buttons: PropTypes.object.isRequired,
 *   error: PropTypes.string,
 *   ready: PropTypes.bool
 * };
 */
class Form extends Accounts.ui.Form {
  render() {
    const { fields, buttons, error, message, ready = true} = this.props;
    return (
      <form className={ready ? "ready" : null} onSubmit={ evt => evt.preventDefault() } className="accounts-ui">
        <Accounts.ui.Fields fields={ fields } />
        <Accounts.ui.Buttons buttons={ buttons } />
        <Accounts.ui.FormMessage message={ message } />
      </form>
    );
  }
}

class Buttons extends Accounts.ui.Buttons {}
class Button extends Accounts.ui.Button {}
class Fields extends Accounts.ui.Fields {}
class Field extends Accounts.ui.Field {}
class FormMessage extends Accounts.ui.FormMessage {}
// Notice! Accounts.ui.LoginForm manages all state logic
// at the moment, so avoid overwriting this one, but have
// a look at it and learn how it works. And pull
// requests altering how that works are welcome.

// Alter provided default unstyled UI.
Accounts.ui.Form = Form;
Accounts.ui.Buttons = Buttons;
Accounts.ui.Button = Button;
Accounts.ui.Fields = Fields;
Accounts.ui.Field = Field;
Accounts.ui.FormMessage = FormMessage;

// Export the themed version.
export { Accounts, STATES };
export default Accounts;

Available components

  • Accounts.ui.LoginForm
    • Accounts.ui.Form
      • Accounts.ui.Fields
        • Accounts.ui.Field
      • Accounts.ui.Buttons
        • Accounts.ui.Button
      • Accounts.ui.FormMessage
      • Accounts.ui.PasswordOrService
      • Accounts.ui.SocialButtons

Extra fields

Example provided by @radzom.

import { Accounts, STATES } from 'meteor/std:accounts-ui';

class NewLogin extends Accounts.ui.LoginForm {
  fields() {
    const { formState } = this.state;
    if (formState == STATES.SIGN_UP) {
      return {
        firstname: {
          id: 'firstname',
          hint: 'Enter firstname',
          label: 'firstname',
          onChange: this.handleChange.bind(this, 'firstname')
        },
        ...super.fields()
      };
    }
    return super.fields();
  }

  translate(text) {
    // Here you specify your own translation function, e.g.
    return this.props.t(text);
  }

  signUp(options = {}) {
    const { firstname = null } = this.state;
    if (firstname !== null) {
      options.profile = Object.assign(options.profile || {}, {
        firstname: firstname
      });
    }
    super.signUp(options);
  }
}

And on the server you can store the extra fields like this:

import { Accounts } from 'meteor/accounts-base';

Accounts.onCreateUser(function (options, user) {
  user.profile = options.profile || {};
  user.roles = {};
  return user;
});

Deprecations

v1.2.11

  • The use of FormMessage in Form has been deprecated in favor of using FormMessages that handles multiple messages and errors. See example: Form.jsx#L43

  • Implementations of Accounts.ui.Field must render a message. See example: Field.jsx#L

Credits

Made by the creative folks at Studio Interact and all the wonderful people using and improving this package.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].