This is a basic node/express app with ability to add users and log them in securely with user authentication. It can be applied to any project that needs user authentication and secure sessions. Take the generic boilerplate and customize it for new projects.
- Sequelize models and migration for user model
- Settings for Postgresql
- Passport and passport local
- Express sessions for logged-in user
- Connect-flash error and success messages on log-in and log-out
Column Name | SQL Type | Notes |
---|---|---|
id | Integer | serial primary key |
createdAt | Date | automatically-generated |
updatedAt | Date | automatically-generated |
firstname | String | - |
lastname | String | - |
String | usernameField for log-in | |
password | String | hashed with bcrypt |
dob | Date | - |
admin | Boolean | admin or regular user |
NOTE: change these fields in model and migration files BEFORE running sequelize db:migrate
Method | Path | Location | Purpose |
---|---|---|---|
GET | / | index.js | Home Page |
GET | /profile | controllers/profile.js | Profile page (authorization req) |
GET | /auth/login | controllers/auth.js | Log-in form page |
POST | /auth/login | controllers/auth.js | Log-in submission + profile redirect |
GET | /auth/signup | controllers/auth.js | Sign-up form page |
POST | /auth/signup | controllers/auth.js | Sign-up submission + redirect to profile |
GET | auth/logout | controllers/auth.js | Logout + redirect to home |
git clone <repo_link> <new_project_name>
createdb <new_db_name>
npm install
- Title in layout.js
- Logo in navbar
- Description/repo link in package.json
- Remove auth boilerplate readme and update readme for new project
- Change database name to new_db_name from above
- Set username/password for your local environment
- Make sure the flavor of SQL is correct for your project
NOTE: if changing from Postgres, need different node_modules
For example, remove dob field or admin field; add username field, etc
Delete or add to both migration and model
sequelize db:migrate
If nodemon is installed globally:
nodemon
Otherwise:
node index.js
- Create a new repository on your personal GitHub account
- Delete the old remote to origin
- Add new repo as the new remote location (can still be called origin)
- git push
git remote remove origin
git remote add origin <new_repo_link?
git add .
git commit -m "new project repo"
git push origin master
NOTE: Do NOT make commits from the new project to the auth boilerplate
Add new models and migrations for your new app.