All Projects → simpletut → Universal React Apollo Registration

simpletut / Universal React Apollo Registration

Licence: mit
Open Source Universal User Registration System – NodeJS React Apollo GraphQL JWT MongoDB

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Universal React Apollo Registration

next-utils
🥩 🍳 A set of Next.js HoC utilities to make your life easier
Stars: ✭ 30 (-93.94%)
Mutual labels:  apollo-client, server-side-rendering
Mern
🎉 This is boilerplate for MERN stack with integrations like Redux and SSR 🎉
Stars: ✭ 77 (-84.44%)
Mutual labels:  mongodb, server-side-rendering
Reactjs Portfolio Mern Website
My Portfolio | Full Stack MERN Application
Stars: ✭ 25 (-94.95%)
Mutual labels:  mongodb, server-side-rendering
Webfluxtemplate
Spring Webflux template application with working Spring Security, Web-sockets, Rest, Web MVC, and Authentication with JWT.
Stars: ✭ 107 (-78.38%)
Mutual labels:  mongodb, json-web-token
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+270.3%)
Mutual labels:  apollo-client, server-side-rendering
Create Social Network
An educational project, demonstrating how to build a large scalable project with Javascript.
Stars: ✭ 853 (+72.32%)
Mutual labels:  apollo-client, mongodb
React Ssr Boilerplate
A boilerplate for server-side rendered React Applications. Includes local auth and GitHub Oauth 2 strategies.
Stars: ✭ 85 (-82.83%)
Mutual labels:  mongodb, server-side-rendering
Next Graphql Blog
🖊 A Blog including a server and a client. Server is built with Node, Express & a customized GraphQL-yoga server. Client is built with React, Next js & Apollo client.
Stars: ✭ 152 (-69.29%)
Mutual labels:  apollo-client, mongodb
Fullstack Apollo Express Mongodb Boilerplate
💥A sophisticated GraphQL with Apollo, Express and MongoDB boilerplate project.
Stars: ✭ 301 (-39.19%)
Mutual labels:  apollo-client, mongodb
Mongodbapp
The easiest way to get started with MongoDB on the Mac
Stars: ✭ 464 (-6.26%)
Mutual labels:  mongodb
Fiora
An interesting open source chat application. Developed with node.js, mongoDB, socket.io and react
Stars: ✭ 4,920 (+893.94%)
Mutual labels:  mongodb
Mongodb
MongoDB driver for Elixir
Stars: ✭ 463 (-6.46%)
Mutual labels:  mongodb
React Music Webapp
一款基于React构建的音乐播放器 A music webapp build with react and antd-mobile
Stars: ✭ 465 (-6.06%)
Mutual labels:  mongodb
Chatty
A WhatsApp clone with React Native and Apollo (Tutorial)
Stars: ✭ 481 (-2.83%)
Mutual labels:  apollo-client
Fullstack Javascript Architecture
✍️ Opinionated project architecture for Full-Stack JavaScript Applications.
Stars: ✭ 464 (-6.26%)
Mutual labels:  mongodb
Nuxt Firebase Sns Example
Nuxt v2 & Firebase(Hosting / Functions SSR / Firestore), Google Auth SNS Example.
Stars: ✭ 485 (-2.02%)
Mutual labels:  server-side-rendering
Testcontainers Spring Boot
Container auto-configurations for spring-boot based integration tests
Stars: ✭ 460 (-7.07%)
Mutual labels:  mongodb
Api Design Node V3
[Course] API design in Node with Express v3
Stars: ✭ 459 (-7.27%)
Mutual labels:  mongodb
Faqguru
🎒 🚀 🎉 A list of interview questions. This repository is everything you need to prepare for your technical interview.
Stars: ✭ 4,653 (+840%)
Mutual labels:  mongodb
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (-2.63%)
Mutual labels:  json-web-token

Open Source Universal User Registration System – NodeJS React Apollo GraphQL JWT MongoDB

Build Status GitHub

Online Demo

As the Demo is hosted on a free Heroku account, the servers its hosted on enter ‘sleep mode’ when not in use. If you notice a delay, please allow a few seconds for the servers to wake up.

YouTube Video Tutorials

Introduction (Getting started)

System includes:

Registration, Login, Dashboard, Email Password, Logout

Account Update, Edit User Profile

Browse Users, Public Profile Pages

Cookie Policy, Privacy Policy, T&C’s, FAQ

404 (Not Found)

The User Registration System is Fully Responsive out the box and you can Restrict Access to any page!

Tech Stack:

  • NodeJS
  • React
  • Server-side Rendered
  • Apollo Client
  • GraphQL
  • MongoDB
  • JSON Web Tokens
  • Webpack
  • SASS
  • ESLint
  • Husky (pre-push)

Top Features:

  • Bcrypt password encryption/verification
  • CKEditor - WYSIWYG editor
  • File Upload – Profile Images
  • Nodemailer – Custom mail server used to send password reset emails
  • Custom ‘Password Reset’ Template (Built with MJML Framework)
  • Multiple Layouts – Create unlimited layouts for pages/routes
  • Toastr - Simple javascript toast notifications
  • 100% FREE & Open Source

Screenshot

Table of Contents

Getting Started

This repository contains the source code for User Registration System. This documentation will cover the installation on your localhost machine, project architecture and working with the app in general.

Project architecture

For a detailed guide through the project architecture and more information on configuring and deploying the system, please watch our YouTube Video Tutorial (Please scroll to the top ^)

├── src
│   ├──_test_
│   ├──assets
│   |  ├── email_templates
│   |  ├── graphics
│   |  └── scss
│   ├──components
│   |  ├── auth
|   |  |   └── editProfile_mutations
│   |  ├── footer
│   |  ├── header
│   |  └── sidebar
│   ├── helpers
|   |   └── renderer
│   ├── hoc
|   |   ├── withAuth
|   |   └── withSession
│   ├── layouts
|   |   └── mainLayout
│   ├── models
|   |   └── User
│   ├── pages
|   |   ├── auth
|   |   |   ├── editProfile
|   |   |   ├── forgotPassword
|   |   |   ├── signIn
|   |   |   ├── signOut
|   |   |   ├── signUp
|   |   |   └── updateAccount
|   |   ├── policiesAndConditions
|   |   |   ├── cookiePolicy
|   |   |   ├── faq
|   |   |   ├── privicyPolicy
|   |   |   └── terms
|   |   ├── 404
|   |   ├── dashboard
|   |   ├── user
|   |   └── users
│   ├── queries
|   |   └── index
│   ├── app
│   ├── client
│   ├── resolvers
│   └── schema
├── user-uploads
│   └── profile-images
├── package.json
├── server.js
├── variables.env
├── webConfig.json
├── webpack.client.js
└── webpack.server.js

Software

Before proceeding, please ensure you have the following software installed on your computer.

  • Node
  • Yarn (optional but recommended)
  • Git command line tools

Useful links

Installation

Please fork a copy of this repository. Forking a repository allows you to freely experiment with changes without affecting the original project. Alternatively download or clone the master branch.

Download & Install Dependencies on your machine

  1. Clone the repo to your machine
git clone <CloneURL>
  1. Within terminal or cmd ensure you have navigated inside the cloned directory and install the dependencies
cd <new-dir> 
yarn install OR npm install

Configure Webpack

Before we can build, run or deploy our app it is important to ensure that the 'webConfig.json' file is configured correctly for our environment.

{
    "siteURL": "http://localhost:3000",
    "environment": "development"
}

Please ensure that 'siteURL' is set to either localhost or your websites domain. You must update this before running a build or deploying your web app.

In the same way, set ‘environment’ to either ‘development’ or ‘production’. This will change the way webpack compiles your code.

Set-up MongoDB (Setting up your database)

This web app uses MongoDB to save, query and process data. Whilst you may have a preference of your service provider (AWS, Microsoft Azure etc…) we will be using ‘mlab’.

Please visit ‘mlab’ register/login to your account.

Link- https://mlab.com/

  1. From your control panel select ‘Create new’
  2. Choose any of the Cloud Provider’s
  3. Select the appropriate ‘Plan Type’ for you. For now, let’s select the ‘Free’ plan
  4. Click Continue
  5. Select the ‘Region’ that’s closest to your location and click continue
  6. Enter a new database name and click continue
  7. Confirm your selections and click ‘Submit order’ (Free)

The database will now be created, and you will have been redirected back to your dashboard.

Adding a User to your database

  1. Under ‘MongoDB Deployments’ click on the database you just created
  2. Select ‘Users’
  3. Select ‘Add database users’
  4. Enter a Username and Password and click ‘Create’

Please remember this information as we will need it later.

Connecting our Registration System to our Database

We need a ‘connection string’ provided by ‘mlab’ to link our Registration System with our Database.

Please ensure that you are still navigated inside the database you just created.

It looks something like this:

To connect using a driver via the standard MongoDB URI:

mongodb://<dbuser>:<dbpassword>@...

Copy this URL as we will need it later.

Configuring our Registration System to Connect to our Database

We are using Node Environment Variables to supply our app with some more sensitive information. This includes our mail server user & password. In addion to our JWT Secret.

To define, please go back to your terminal or cmd and write the following command

export db_connection_string=<Your-connection-string>

Please note: Windows users should use 'set' instead of 'export'

JSON Web Tokens

We store a JSON Web Token within a Cookie to verify users.

For security reasons, these Tokens have been configured to expire after 1 hour at which point the user will be asked to login again before continue browsing the website. (The expiration time can be updated within the signup and login resolvers).

Whenever we check the validity of a Token, we compare it will a ‘Secret Key’ that is stored as a Node Environment Variable.

To define, please go back to your terminal or cmd and write the following command

export jwt_secret_key=<Your-json-web-token-secret-key>

Please note: Windows users should use 'set' instead of 'export'

This should be a random string of numbers and characters.

Mail Server (Send password recovery email)

We use a package called ‘Nodemailer’ to handle the sending of emails from our Node Server.

As we are using one-way password encryption, the account recovery tool automatically generates a new secure password and sends it to the email associated with the account.

Before you can use this feature, you will need to configure ‘Nodemailer’.

  1. Open ‘config/default.json’ in your chosen text editor
  2. Update your mail server host and from email address.

For security reasons we store your mail server 'user' and 'password' in Node Environment Variables.

To define, please go back to your terminal or cmd and write the following commands

export mailServer_user=<Your-mail-server-user>
export mailServer_pass=<Your-mail-server-password>

Please note: Windows users should use 'set' instead of 'export'

You may need to contact your provider for this information

Run a Build

Before we can lunch the project, we need to run a build

yarn run build OR npm run build 

Lunch/Run the project

Now we have a build, lets run the project

yarn run dev OR npm run dev 

Your project is now running on: http://localhost:3000

Server & Client Bundles

Webpack outputs both a Server and Client bundle.

For security reasons, the server bundle exits outside of the public directory, which means that the file is NOT publicly accessible.

Webpack is also configured not to bundle any libraries that exist in the 'node_modules' folder into the server bundle as they are not needed.

Unit tests

Writing unit tests is recommended for any new features or logic that you develop.

Whilst we are primarily using 'Jest' (framework from Facebook), to write our unit tests we are using a number of other libraries for testing. Please see the 'package.json' file for more information.

We are currently writing tests for the following:

  • Components
  • Queries
  • Mutations

There are two commands you can use to run tests.

  1. yarn test OR npm test
  • This will run your initial tests.
  1. yarn test-coverage OR npm test-coverage
  • Shows test coverage across our application.

Please note: not all code within our project requires testing or is testable.

When should I run these tests?

You should run these unit tests before pushing any work to a remote branch. Please do not approve any PR’s into the dev branch without the proper unit tests having been written.

In the event a test fails, please ensure any relevant errors are resolved prior to committing the changes or creating a new PR.

General usage

Create new pages

  1. Create a file in the following directory ‘src/pages’

To help maintain consistence please use the same naming conventions as the other files. (camel casing)

  1. Build your new page. For example:
import React from 'react';

class NewPage extends React.Component {
    render(){
        return(
            <div>

            </div>
        )
    }
}

export default NewPage;

  1. Open ‘src/app.js’ and import your new Page Component
import NewPage from './pages/newPage;
  1. Add a new route to the Root constant
<Route path="/new-page" render={props => (
    <MainLayout>
        < NewPage {...props} session={session} />
    </MainLayout>
)} />

Based on the example above, you can visit the new page via the following URL:

http://localhost:3000/new-page

Restrict Access (Authenticated Users Only)

Follow these steps to prevent unauthenticated users from accessing your chosen pages/routes

  1. Open ‘src/app.js’ and find your chosen route within the ‘Root’ constant
  2. If not already pass the ‘session’ as props to your Component
<Route path="/dashboard" render={props => (
    <MainLayout>
        <Deshboard {...props} session={session} />
    </MainLayout>
)} />

Notice the ‘session={session}’ on the ‘Deshboard’ Component.

  1. Open you’re the JS file accociated with your Chossen Compoent. For example, ‘src/pages/dashboard.js’
  2. Import ‘withAuth’. This is a higher order component.
import withAuth from './../hoc/withAuth';

Please ensure that the path is correct based on your component file.

  1. Wrap your export with our our ‘withAuth’ higher order component.
export default withAuth(session => session && session.getCurrentUser)(Dashboard);

Please note: If you copy/paste this line, please ensure you update ‘Dashboard’ with the name of the Class your exporting.

That’s it!

User will now need to LogIn before accessing this page/route

Custom Layouts

You can create a custom layout for any page/route.

  1. Create a new layout file within ‘src/layouts’
  2. Ensure you have a constructer at the top of your class
constructor(props) {
    super(props)
}

  1. Place the following code within your layout, wherever you want to render your routes
{this.props.children}
  1. Open ‘src/app.js’ and import your new layout
import LayoutComponent from './layouts/ layoutComponent;
  1. Within your ‘Root’ constant, create your new route and wrap the route with your layout Component
<Route path="/my-new-page" render={props => (
    < LayoutComponent >
        <MyRoute {...props} session={session} />
    </ LayoutComponent>
)} />

Custom Page titles and SEO

We use a package called ‘helmet’ to set custom page titles and add meta tags on pages within our app.

  1. Open the page component you wish to add custom page title
  2. Copy the following code just above the render method:
head() {
    return (
        <Helmet bodyAttributes={{ class: "myClassName" }}>
            <title>My new page title</title>
        </Helmet>
    );
}
  1. Call this method anywhere within your return statement
render() {

    return (
        <div className="grid pageHeaderSection">
        {this.head()}
            <div className="column column_12_12">
                <div className="content_wrap">
                    <h2>Users</h2>
                    <p className="desc">
                        Lorem Ipsum is simply dummy text of the printing and typesetting…

Styles

We are using SCSS (CSS pre-processor/bracketed version of SASS) to enable us to write cleaner and more reusable css code.

CSS

In order to ensure the integrity of the project and long-term maintainability, we recommend the following rules:

  • Media queries should be written/maintained within '_responsive.scss'.
  • REM CSS measurement units:

We are using rem's to style our app. Whilst you should not use any other measurement unit, it is correct to use ‘px’ for certain properties. For example, you should still use 'px' for setting a border or the width of a media query to ensure more accurate break points.

The root font size is set to '10px'. This means the calculation required to implement rem’s is simple: (target font size / 10 OR 18 / 10 = 1.8rem).

'config.js'

Please utilize our configuration partial file wherever possible. This contains global variables for generic/brand colours, keyframes, mixins and more! For consistency please reference these instead of redefining where possible (or add to this file).

12 Col Grid Boiler template

We are using a 12 Column Grid that works as follows:

The grid has 12 columns

Each columns width is a % value that can be calculated using the following:

Target Columns (Example '6')
Minus Number of Total Columns (12)
Times 100 = 50%

Example HTML mark-up for a 2-column layout:

<div class="grid">
 
  <div class="column column_6_12">
    Half
  </div>
  
  <div class="column column_6_12">
    Half
  </div>
 
<div>

Each column has a ‘20px’ gutter/ Each column has 10px padding on either side.

The grid should not be used within areas that require custom mark-up (such as your header/footer) to avoid having to override default styling. This will ensure the integrity of the code. Please DO NOT apply any styling to the grid directly. These should be global classes which are not overridden (ensures you will not break styling in other places).

To centre your content, simply apply a 'max-width' to the parent wrapper '.grid'. You can either set this globally within the '_css_grid.scss' partial file or target it specifically via a custom parent class.

Looking for something similar?

Open Source Universal React Redux Boilerplate

Acknowledgements

This software was developed by Ashley Bibizadeh.

License

The User Registration System is open source software licensed as MIT.

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].