Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Send token response on email verification
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 16, 2020
1 parent 3f9bbae commit 70c5328
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ export class AuthController {
}

@Post('verify-email')
async verifyEmail(@Body() data: VerifyEmailDto) {
return this.authService.verifyEmail(data.token);
async verifyEmail(
@Ip() ip: string,
@Headers('User-Agent') userAgent: string,
@Body() data: VerifyEmailDto,
): Promise<TokenResponse> {
return this.authService.verifyEmail(ip, userAgent, data.token);
}

@Post('forgot-password')
Expand All @@ -126,7 +130,7 @@ export class AuthController {
@Ip() ip: string,
@Headers('User-Agent') userAgent: string,
@Body() data: ResetPasswordDto,
) {
): Promise<TokenResponse> {
return this.authService.resetPassword(
ip,
userAgent,
Expand Down
8 changes: 6 additions & 2 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ export class AuthService {
return this.loginResponse(ipAddress, userAgent, user);
}

async verifyEmail(token: string): Promise<Expose<emails>> {
async verifyEmail(
ipAddress: string,
userAgent: string,
token: string,
): Promise<TokenResponse> {
const { id } = this.tokensService.verify<{ id: number }>(
EMAIL_VERIFY_TOKEN,
token,
Expand Down Expand Up @@ -427,7 +431,7 @@ export class AuthService {
},
});
}
return this.prisma.expose<emails>(result);
return this.loginResponse(ipAddress, userAgent, result.user);
}

getOneTimePassword(secret: string): string {
Expand Down

0 comments on commit 70c5328

Please sign in to comment.