Skip to content

wannabeSE/nestjs-google-jwt-session-auth-system

Repository files navigation

Nest Logo

Description

This projects provides jwt, session and google oauth authentication system.

Developed using:

  • NestJS
  • MongoDB

Installation

$ pnpm install

Running the app

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

Test

# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov

SAuth

API Reference

To create new user

  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'}

Sign In with Google [uses session log in]

  GET /api/v1/auth/google/login
Parameter Type Description
google account google account Required Google account.

returns {userID: 90347805124095684, email: 'abc@xyz.com'}

Log In with Session

  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'}

Log In with JWT

  POST /api/v1/auth/jwt/login
Parameter Type Description
email string Required
password string Required

returns {access_token: efgtg5g352gh25gh5h5h5hh3, refresh_token: ghh7fdfsdfsdafsdavfhykjukgfh}

To get info of logged in user [session expires in 1 day]

  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'}

To extend the time of previously assigned access token

  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]

To log the user out

  GET /api/v1/auth/session/logout

To get all users

  GET /api/v1/user/all
Parameter (Header) Type Description
Authorization: Bearer <TOKEN> string Required

returns [ {user_object}, {user_object} ]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published