This is a boilerplate for an Express App with local user authentication.It exists so I have a customized boilerplate and don't have to start from scratch on all my projects.
- Local Auth (email. and passowrd)
- Passport and passport-local
- Sessions for saving user info and displaying flash messages
- Settings for PostgresSQL and Sequelize
- Hashed passwords
- EJS templating and EJS layouts
- Sequelize User model
- Materialize styling - nav and footer
Column | Type | Notes |
---|---|---|
id | Integer | Serial primary key |
firstname | String | Required Length > 1 |
lastname | String | - |
String | Unique Loging | |
password | String | Hash |
birthday | Date | - |
admin | Booleam | Defaulted to False |
pic | String | - |
bio | Text | - |
createdAt | Date | Automatically added by Sequelize |
updatedAt | Date | Automatically added by Sequelize |
Routes in index.js (main)
Method | Path | Purpose |
---|---|---|
GET | / |
Home Page |
GET | * |
Catch-all for 404s |
Routes in controllers/auth.js
Method | Path | Purpose |
---|---|---|
GET | /auth/login |
Render login form |
POST | /auth/login |
Process login data |
GET | /auth/signup |
Render signup form |
POST | /auth/signup |
Process signup data |
GET | /auth/logout |
Remove user from session + redirect |
Routes in controllers/profile.js
Method | Path | Purpose |
---|---|---|
GET | /profile/user |
Show user dashboard (authorized user only) |
GET | /profile/admin |
Show admin dashboard (authorized admin only) |
GET | /profile/guest/:id |
View user dashboard as guest View user dashboard as guest (authorized user only) |
Run the following command on the terminal
git clone <repo_link> <new_name>
For example
git clone git@[email protected]/alexhan77/node-auth-boiler.git shiny-new-project
npm i
Remove defaulty stuff. For example:
- Title in
layout.ejs
- Logo field in the nav bar
- Description and Repository fields in package.json
- Remove this boilerplate's readme content
- Switch Favicon to project-specific one (in
layout.ejs
head section)
createdb <new_db_name>
For Example
createdb shiny_db
In config/config.json
, update the database name to the one created in step 4. Other settings likely okay, but check username, password, and dialect.
For example, if the new project doesn't need a birthday field, then delete it from the user model and user migration files.
sequelize db:migrate
touch .env
Alternatively just create via text editor
Include the following .env variables:
- SESSION_SECRET - this is a key for the session to use
with nodemon
nodemon
without nodemon
node index.js
Currently if we run this command:
git remote -v
It will show origin
as being hooked up to the boilerplate repository. We want a fresh repository instead, so let's delete the origin remote:
git remote remove origin
Via the Github website. Follow directions as they show up when you create a new repository:
git init
git add .
git commit -m "Initial Commit"
git remote add origin <new_repo_link>
git push origin master
Happy developing!