This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
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.
feat: add confirmation mail register
- Loading branch information
ludovicGendre
committed
Jan 21, 2022
1 parent
02c7a4e
commit 296a50b
Showing
8 changed files
with
69 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ SALT="EAsCKIFVCV5CcfJc7M24Zgegy0j9zEuu" | |
EMAIL_SERVICE="gmail" | ||
EMAIL_USER="[email protected]" | ||
EMAIL_PASSWORD="Secret00" | ||
JWT_VERIFICATION_TOKEN_SECRET="7AnEd5epXmdaJfUrokkQ" | ||
JWT_VERIFICATION_TOKEN_EXPIRATION_TIME=21600 | ||
EMAIL_CONFIRMATION_URL="https://localhost:3000/confirm-email" |
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
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import EmailService from '../email.service'; | ||
|
||
interface VerificationTokenPayload { | ||
email: string; | ||
} | ||
|
||
@Injectable() | ||
export class EmailConfirmationService { | ||
constructor( | ||
private readonly jwtService: JwtService, | ||
private readonly emailService: EmailService, | ||
) {} | ||
|
||
public sendVerificationLink(email: string) { | ||
const payload: VerificationTokenPayload = { email }; | ||
const token = this.jwtService.sign(payload, { | ||
secret: process.env.JWT_VERIFICATION_TOKEN_SECRET, | ||
expiresIn: `${process.env.JWT_VERIFICATION_TOKEN_EXPIRATION_TIME}s`, | ||
}); | ||
|
||
const url = `${process.env.EMAIL_CONFIRMATION_URL}?token=${token}`; | ||
|
||
const text = `Welcome to the application. To confirm the email address, click here: ${url}`; | ||
|
||
return this.emailService.sendMail({ | ||
to: email, | ||
subject: 'Email confirmation', | ||
text, | ||
}); | ||
} | ||
} |
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