This projects provides jwt, session and google oauth authentication system.
Developed using:
- NestJS
- MongoDB
$ pnpm install
# development
$ pnpm run start
# watch mode
$ pnpm run start:dev
# production mode
$ pnpm run start:prod
# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov
Must Run on http://localhost:3000
POST /api/v1/user/create-user
Parameter | Type | Description |
---|---|---|
username |
string |
Required |
email |
string |
Required |
password |
string |
Required |
returns {userID: 90347805124095684, email: 'abc@xyz.com'}
GET /api/v1/auth/google/login
Parameter | Type | Description |
---|---|---|
google account |
google account |
Required Google account. |
returns {userID: 90347805124095684, email: 'abc@xyz.com'}
POST /api/v1/auth/session/login
Parameter | Type | Description |
---|---|---|
username |
string |
Required |
password |
string |
Required |
request body = {username: 'abc@gmail.com', password:'123456'} [username will be read as email]
returns {userID: 90347805124095684, email: 'abc@xyz.com'}
POST /api/v1/auth/jwt/login
Parameter | Type | Description |
---|---|---|
email |
string |
Required |
password |
string |
Required |
returns {access_token: efgtg5g352gh25gh5h5h5hh3, refresh_token: ghh7fdfsdfsdafsdavfhykjukgfh}
GET /api/v1/auth/session/profile
Parameter (Header) | Type | Description |
---|---|---|
Cookie: connect.sid=78cfbbcub8298f9cen9c02ncie |
string |
Required |
returns {userID: 90347805124095684, email: 'abc@xyz.com'}
To get info of logged in user [Access Token expires in 6hrs, refresh token will be available for 24hrs].
POST /api/v1/auth/jwt/profile
Parameter (Header) | Type | Description |
---|---|---|
Authorization: Bearer <TOKEN> |
string |
Required |
returns {userID: 90347805124095684, email: 'abc@xyz.com'}
POST /api/v1/auth/jwt/refresh-token
Parameter | Type | Description |
---|---|---|
refresh_token as Request Body |
string |
Required |
returns {access_token: jgsdggioergiohigoeoighorgh4pjfgl}
[only extends the expiration time. No user info is included]
GET /api/v1/auth/session/logout
GET /api/v1/user/all
Parameter (Header) | Type | Description |
---|---|---|
Authorization: Bearer <TOKEN> |
string |
Required |
returns [ {user_object}, {user_object} ]