Express authentication template using Passport + flash messages + custom middleware
- 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
Column Name | Data Type | Notes |
---|---|---|
id | Integer | Serial Primary Key, Auto-generated |
name | String | Must be provided |
String | Must be unique / used for login | |
password | String | Stored as a hash |
createdAt | Date | Auto-generated |
updatedAt | Date | Auto-generated |
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 |
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'!
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.
npm install
(Or just npm i
for short)
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
Using the sequelize command line interface, you can create a new database from the terminal.
createdb <new_db_name>
- Change the database name
- Other settings are likely okay, but check username, password, and dialect
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.
sequelize db:migrate
- SESSION_SECRET: Can be any random string; usually a hash in production
- PORT: Usually 3000 or 8000
nodemon
or
node index.js