Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/local user login #10

Merged
merged 59 commits into from
Sep 3, 2023
Merged

Feat/local user login #10

merged 59 commits into from
Sep 3, 2023

Conversation

a20688392
Copy link
Collaborator

@a20688392 a20688392 commented Jul 5, 2023

This PR does three things

  1. Setup Local Passport and unit test.
  2. Setup JWT Passport and unit test.
  3. Local user login and unit test.
  4. Add a script to test one file.
  5. Add Swagger documentation for local login and refresh token API.

1. Setup Local Passport and unit test.

use for user login, username/password authentication mechanism.

Install @nestjs/passport, passport, passport-local

  • local auth guard
    • check the input data fields.
  • local strategy
  • unit test
    • local strategy
      • should return user payload if user is valid
      • should throw UnauthorizedException if user is invalid
    • local auth guard
      • should return true if user is valid
      • should return false if user is invalid
      • should return BadRequest and 400 http code when field format validation failed.

2. Setup JWT Passport and unit test.

use for user Verify identity.

Install @nestjs/jwt,passport-jwt, @types/passport-jwt

  • jwt setting
    • acces token default effective time is 1h.
    • refresh token default effective time is 7d.
  • jwt strategy
    • use access or refresh token when valid sucess when return object JwtUser:{email, id}
  • unit test
    • jwt access guard
      • should be defined
      • should return true for a valid JWT
      • should throw an error for an expired JWT
    • jwt refresh guard
      • should be defined
      • should return true for a valid JWT
      • should throw an error for an expired JWT

3. Local user login and unit test.

local user login, when valid sucess will return access token and refresh token

  • unit test
    • auth controller
      • function login
        • should return a token and 201 http code when account information is correct.
        • should return access, refresh token and 201 http code when refresh token is correct.
    • auth service
      • function login
        • should be login successfully.
      • function validateUser
        • should be validate successfully.
        • should be validate failure.
      • function generate Token
        • should generate access token
        • should generate refresh token
    • user service
      • function find user
        • should be found a user

4. Add a script to test one file.

"test:one": "jest --testPathPattern",

yarn test `fileName`

5. Add Swagger documentation for local login and refresh token API.

  • auth
    • login
    • refresh token

@a20688392 a20688392 requested a review from moontai0724 July 5, 2023 14:18
@moontai0724 moontai0724 changed the title Feat/localuser login Feat/local user login Jul 8, 2023
Copy link
Member

@moontai0724 moontai0724 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments above

@a20688392 a20688392 force-pushed the feat/localuser-login branch from e058f3b to 701a7ef Compare August 9, 2023 15:40
@a20688392 a20688392 force-pushed the feat/localuser-login branch from 701a7ef to 8f55f55 Compare August 10, 2023 09:53
@a20688392 a20688392 force-pushed the feat/localuser-login branch from 57fa5d2 to f9dd2ea Compare August 10, 2023 15:38
@a20688392 a20688392 requested a review from moontai0724 August 25, 2023 10:12
Copy link
Member

@moontai0724 moontai0724 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect! some small advices

@a20688392 a20688392 requested a review from moontai0724 August 31, 2023 15:01
@a20688392 a20688392 force-pushed the feat/localuser-login branch 4 times, most recently from 69431ab to a3f71c3 Compare September 1, 2023 14:05
@a20688392 a20688392 force-pushed the feat/localuser-login branch from 6c7423c to ee6b2d1 Compare September 2, 2023 02:06
@a20688392 a20688392 merged commit 743ce1f into develop Sep 3, 2023
@a20688392 a20688392 deleted the feat/localuser-login branch September 3, 2023 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants