Skip to content

Commit

Permalink
Fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
PhamAnhHoang committed Feb 16, 2024
1 parent 9cf46d9 commit 101bd73
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
25 changes: 14 additions & 11 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import {
ResetPasswordRequestDto,
SignUpWithEmailCredentialsDto
} from '@isomera/dtos'
import { JwtPayload, LoginResponseInterface } from '@isomera/interfaces'
import {
JwtPayload,
LoginResponseInterface,
LoginWith2FAPayload,
LoginWithEmailPayload,
SignTokenInterface
} from '@isomera/interfaces'
import { UserService } from '../user/user.service'
import { MailerService } from '../mailer/mailer.service'
import { ConfirmCodeService } from '../user/confirm-code.service'
Expand Down Expand Up @@ -89,7 +95,7 @@ export class AuthService {

console.log('xxx', user)

const payload = {
const payload: LoginWithEmailPayload = {
email: user.email
}
const { refresh_token, access_token } = this.signToken(payload)
Expand All @@ -116,27 +122,24 @@ export class AuthService {
return user
}

signToken(payload: object): {
refresh_token: string
access_token: string
} {
signToken<T>(payload: T): SignTokenInterface {
return {
refresh_token: this.generateRefreshToken(payload),
access_token: this.generateAccessToken(payload)
}
}

public generateAccessToken(payload: object): string {
return this.jwtService.sign(payload, {
public generateAccessToken<T>(payload: T): string {
return this.jwtService.sign(payload as object, {
expiresIn: `${this.configService.get<string>(
'JWT_ACCESS_TOKEN_EXPIRATION_TIME',
'260'
)}s`
})
}

public generateRefreshToken(payload: object): string {
return this.jwtService.sign(payload, {
public generateRefreshToken<T>(payload: T): string {
return this.jwtService.sign(payload as object, {
expiresIn: `${this.configService.get<string>(
'JWT_REFRESH_TOKEN_EXPIRATION_TIME'
)}s`
Expand Down Expand Up @@ -329,7 +332,7 @@ export class AuthService {
throw new UnauthorizedException('Code is incorrect.')
}

const payload = {
const payload: LoginWith2FAPayload = {
email: user.email,
isTwoFactorAuthenticationEnabled: !!user.isTwoFAEnabled,
isTwoFactorAuthenticated: true
Expand Down
3 changes: 1 addition & 2 deletions apps/platform/src/hooks/Recover2FAHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const useRecoveryHook = (options: Options) => {
}

const validationSchema = Yup.object({
code: Yup.string().required('2FA code is required'),
email: Yup.string().email('Invalid email').required('Email is required')
code: Yup.string().required('2FA code is required')
})

const onSubmit = async (values: Recover2FAData) => {
Expand Down
4 changes: 4 additions & 0 deletions libs/interfaces/src/auth/signToken.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface SignTokenInterface {
refresh_token: string
access_token: string
}
1 change: 1 addition & 0 deletions libs/interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './auth/loginResponse.interface'
export * from './auth/logoutResponse.interface'
export * from './organization/Organization.interface'
export * from './user/enum/user-organization-enum'
export * from './auth/signToken.interface'

0 comments on commit 101bd73

Please sign in to comment.