Git Product home page Git Product logo

authapp's Introduction

Express Authentication

Express authentication template using Passport + flash messages + custom middleware

What it includes

  • Sequelize user model / migration
  • Settings for PostgreSQL
  • Passport and passport-local for authentication
  • Sessions to keep user logged in between pages
  • Flash messages for errors and successes
  • Passwords that are hashed with BCrypt
  • EJS Templating and EJS Layouts

User Model

Column Name Data Type Notes
id Integer Serial Primary Key, Auto-generated
name String Must be provided
email String Must be unique / used for login
password String Stored as a hash
createdAt Date Auto-generated
updatedAt Date Auto-generated

Default Routes

Method Path Location Purpose
GET / server.js Home page
GET /auth/login auth.js Login form
GET /auth/signup auth.js Signup form
POST /auth/login auth.js Login user
POST /auth/signup auth.js Creates User
GET /auth/logout auth.js Removes session info
GET /profile server.js Regular User Profile

Steps To Use

1. Create a new repo on Github and use your 'express-authentication' as the template

When we are finished with this boilerplate, we are going to make it a template on Github that will allow us to create a new repo on Github with all this code already loaded in.

  • Go to github.com and create a new repository. In the template dropdown, choose this template.
  • Clone your new repo to your local machine
  • Get Codin'!

2. Delete any .keep files

The .keep files are there to maintain the file structure of the auth. If there is a folder that has nothing in it, git won't add it. The dev work around is to add a file to it that has nothing in it, just forces git to keep the folder so we can use it later.

3. Install node modules from the package.json

npm install

(Or just npm i for short)

4. Customize with new project name

Remove defaulty type stuff. Some areas to consider are:

  • Title in layout.ejs
  • Description/Repo Link in package.json
  • Remove boilerplate's README content and replace with new project's readme

5. Create a new database for the new project

Using the sequelize command line interface, you can create a new database from the terminal.

createdb <new_db_name>

6. Update config.json

  • Change the database name
  • Other settings are likely okay, but check username, password, and dialect

7. Check the models and migrations for relevance to your project's needs

For example, if your project requires a birthdate field, then don't add that in there.

When changing your models, update both the model and the migration.

8. Run the migrations

sequelize db:migrate

9. Add a .env file with the following fields:

  • SESSION_SECRET: Can be any random string; usually a hash in production
  • PORT: Usually 3000 or 8000

10. Run server; make sure it works

nodemon

or

node index.js

authapp's People

Contributors

romebell avatar

Watchers

 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.