Skip to content

Commit

Permalink
fix: user should be redirected to otp verification page
Browse files Browse the repository at this point in the history
  • Loading branch information
niyobertin committed Jun 28, 2024
1 parent 978c4a0 commit 18dd671
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/controllers/userControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,16 @@ export const tokenVerification = async (req: Request, res: Response) => {

try {
const decoded = await decodeMagicLinkToken(token);
const link = `${env.fe_url}/2fa-verify`;
//@ts-ignore
const { otp, userId } = decoded;
if (otp) {
const user = await User.findOne({ where: { id: userId }, attributes: { exclude: ["password"] } });
//@ts-ignore
const accessToken = await generateToken(user);
const link = process.env.NODE_ENV !== "production"? `${env.redirect_local_url}/2fa-verify?token=${accessToken}`: `${env.redirect_remote_url}/2fa-verify?token=${accessToken}`;
return res.status(200).redirect(link);
} else {
return res.status(401).json({
message: "Token expired",
});
return res.status(401).redirect(link);
}
} catch (error: any) {
return res.status(500).json({
Expand Down Expand Up @@ -202,7 +200,7 @@ export const handleSuccess = async (req: Request, res: Response) => {
token = await generateToken(foundUser);
}

const link = process.env.NODE_ENV !== "production"? `${env.redirect_local_url}/login?token=${token}`: `${env.redirect_remote_url}/login?token=${token}`;
const link = process.env.NODE_ENV !== "production"? `${env.fe_url}/login?token=${token}`: `${env.fe_url}/login?token=${token}`;
return res.status(200).redirect(link);


Expand Down
3 changes: 1 addition & 2 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export const env = {
stripe_secret: process.env.STRIPE_SECRET_KEY as string,
password_expiration_time: process.env.TIME_FOR_PASSWORD_EXPIRATION as string,
ADS_URL: process.env.ADS_URL as String,
redirect_local_url:process.env.REDIRECT_LOCAL_URL as string,
redirect_remote_url:process.env.REDIRECT_REMOTE_URL as string
fe_url:process.env.FE_URL as string,
};
3 changes: 1 addition & 2 deletions src/utils/jsonwebtoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const generateToken = async (user: IUser) => {
id:user.id,
roleId:user.roleId,
name:user.name,
email: user.email,
password: user.password,
email: user.email
},
`${env.jwt_secret}`,
{ expiresIn: "72h" },
Expand Down

0 comments on commit 18dd671

Please sign in to comment.