A nodejs server api for user authentication and use react to design frontend
You can quickly setup a sample heroku application by clicking the button below.
- MongoDB - Our Database v3.2
- Expressjs - API Server
- Nodejs - Backend Framework v7.1.0
- NPM - Package Management v3.10.9
PORT
SECRET_KEY
MONGO_CONNECTION
$ cd server
$ npm install
$ cd ../client
$ npm install
server/config/database.js
database and jwt secret configuration, default using system variables
- secret - jwt auth secret
- database - database connection
- Mongoose - mongodb object modeling
- Simple JWT - token use
- Morgan - HTTP request logger middleware for node.js
- moment - date parse
- bcrypt-nodejs - ecrypt password
- edit server/config/database.js or system variable for
MONGO_CONNECTION
、SECRET_KEY
- database connection and jwt secret- edit server/config/initial.js - super admin account and role's permissions
- export
API_ENDPOINT
with system variable, allow client connection with server endpoint.
- server development:
npm run dev:server
- client development:
npm run dev:client
, default port8080
npm run build:client
npm start
- post
/api/initialize
to create roles and super admin account- post
api/users
- create new account- post
api/users/login
- login and get jwt token then frontend can store this token to use other api- use request header:
{Authorization: (jwt token)}
when use other api
Check token valid
/api/users/logout
Check token valid and expired
/api/users/:id
/api/users/me
-
admin
delete
- other users and rolesget
- all users and rolespost
- user and roleput
- all users and other user's role
-
user
delete
- selfget
- selfpost
- signupput
- self but cannot update role
-
request header - Authorization (json web token)
-
api - api root
-
api/initialize
post - create roles and admin user
-
api/users
post - create new user
-
api/users/login
post - login and get jwt token
-
api/users/me
get - get current user info
-
api/users/:id
delete - delete user
get - get user info
put - update username、displayName only superadmin can update other user's role
- npm install --dev
- npm run test:server
- admin dashboard
- edit role name
- edit password
- add more test case for permissions
- add business logic extension framework document
- add swagger ui