-
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.
send verification email after signing up
- Loading branch information
1 parent
f5fcbf5
commit b3b60a6
Showing
8 changed files
with
114 additions
and
54 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,31 @@ | ||
import nodemailer from "nodemailer"; | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS, | ||
}, | ||
}); | ||
|
||
export function sendVerificationEmail(email: any) { | ||
const verificationLink = `http://yourdomain.com/verify-email?token=token}`; | ||
|
||
const mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: email, | ||
subject: "Email Verification", | ||
text: `Please verify your email by clicking on the following link: ${verificationLink}`, | ||
html: `<p>Please verify your email by clicking on the following link:</p><a href="${verificationLink}">Verify Email</a>`, | ||
}; | ||
|
||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
console.error("Error sending email:", error); | ||
} else { | ||
console.log("Email sent:", info.response); | ||
} | ||
}); | ||
} |
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,17 +1,20 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import { UserAttributes } from '../types/user.types'; | ||
import dotenv from 'dotenv'; | ||
import jwt from "jsonwebtoken"; | ||
import { UserAttributes } from "../types/user.types"; | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
const generateToken = async (user: UserAttributes) => { | ||
return jwt.sign({ | ||
role: user.role, | ||
email: user.email, | ||
id: user.id | ||
}, process.env.JWT_SECRET || "", { | ||
expiresIn: '24h' | ||
}); | ||
} | ||
|
||
export { generateToken }; | ||
return jwt.sign( | ||
{ | ||
role: user.role, | ||
email: user.email, | ||
id: user.id, | ||
}, | ||
process.env.JWT_SECRET || "", | ||
{ | ||
expiresIn: "24h", | ||
} | ||
); | ||
}; | ||
export { generateToken }; |