-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
139 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './context' | ||
export * from './payload' |
3 changes: 3 additions & 0 deletions
3
apps/levansy-access-service/src/domain/interface/auth/payload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type AuthPayload = { | ||
userId: string | ||
} |
1 change: 1 addition & 0 deletions
1
apps/levansy-access-service/src/domain/interface/external/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './puppeteer-service' | ||
export * from './storage-service' | ||
export * from './jwt-service' |
6 changes: 6 additions & 0 deletions
6
apps/levansy-access-service/src/domain/interface/external/jwt-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const JwtServiceToken = Symbol('JwtService') | ||
|
||
export interface IJwtService { | ||
sign(payload: any): string | ||
verify(token: string): any | ||
} |
44 changes: 44 additions & 0 deletions
44
apps/levansy-access-service/src/domain/use-case/auth/login.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { BadRequestException, Inject, Injectable } from '@nestjs/common' | ||
import { LoginExceptionMsg } from '@diut/levansy-common' | ||
import * as argon2 from 'argon2' | ||
|
||
import { IUseCase } from '../interface' | ||
import { UserFindOneUseCase } from '../user/find-one' | ||
import { User } from 'src/domain/entity' | ||
import { JwtService } from '@nestjs/jwt' | ||
import { AuthPayload } from 'src/domain/interface' | ||
|
||
export type AuthLoginUseCaseInput = { username: string; password: string } | ||
export type AuthLoginUseCaseOutput = User & { jwtAccessToken: string } | ||
|
||
@Injectable() | ||
export class AuthLoginUseCase | ||
implements IUseCase<AuthLoginUseCaseInput, AuthLoginUseCaseOutput> | ||
{ | ||
constructor( | ||
private userFindOneUseCase: UserFindOneUseCase, | ||
private jwtService: JwtService, | ||
) {} | ||
|
||
async execute(input: AuthLoginUseCaseInput) { | ||
const { username, password } = input | ||
|
||
const user = await this.userFindOneUseCase.execute({ username }) | ||
if (!user) { | ||
// TODO: abtract domain exception and logging | ||
throw new BadRequestException(LoginExceptionMsg.USERNAME_NOT_EXIST) | ||
} | ||
|
||
const isCorrect = await argon2.verify(user.password, password) | ||
if (!isCorrect) { | ||
throw new BadRequestException(LoginExceptionMsg.WRONG_PASSWORD) | ||
} | ||
|
||
const authPayload: AuthPayload = { | ||
userId: user._id, | ||
} | ||
const jwtAccessToken = await this.jwtService.signAsync(authPayload) | ||
|
||
return { ...user, jwtAccessToken } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
apps/levansy-access-service/src/infrastructure/auth/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { SetMetadata } from '@nestjs/common' | ||
|
||
export const JWT_STRATEGY_KEY = 'auth.jwt' | ||
|
||
export const SKIP_JWT_KEY = 'SKIP_JWT_KEY' | ||
export const SkipJWTGuard = SetMetadata(SKIP_JWT_KEY, true) |
25 changes: 21 additions & 4 deletions
25
apps/levansy-access-service/src/infrastructure/auth/context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/levansy-access-service/src/infrastructure/auth/guards/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './jwt.guard' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from './module' | ||
|
||
export * from './guards' | ||
export * from './strategies' | ||
export * from './common' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/levansy-access-service/src/infrastructure/auth/strategies/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './jwt.strategy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
apps/levansy-access-service/src/presentation/http-controller/v1/auth/common.ts
This file was deleted.
Oops, something went wrong.
29 changes: 7 additions & 22 deletions
29
apps/levansy-access-service/src/presentation/http-controller/v1/auth/controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
apps/levansy-access-service/src/presentation/http-controller/v1/auth/guards/index.ts
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...evansy-access-service/src/presentation/http-controller/v1/auth/guards/local-auth.guard.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
apps/levansy-access-service/src/presentation/http-controller/v1/auth/strategies/index.ts
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
...ansy-access-service/src/presentation/http-controller/v1/auth/strategies/local.strategy.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.