51 |
Follow the following link
52 |
Please follow
53 | this link
54 | to reset your password
55 |
56 |
57 | `,
58 | });
59 | }
60 | } catch (error: any) {
61 | return res.status(400).send({ message: error.message });
62 | }
63 |
64 | // Success
65 | res.status(200).json({ success: true });
66 | } else if (req.method === 'PUT') {
67 | const { tokenId, password } = req.body;
68 |
69 | // Get token from DB
70 | const token = await Token.findOne({ token: tokenId });
71 |
72 | if (!token) {
73 | return res.status(400).json({
74 | success: false,
75 | message: 'Invalid or expired password reset token',
76 | });
77 | }
78 |
79 | // Return user
80 | const user = await User.findOne({ _id: token.userId });
81 |
82 | // Hash password before resetting
83 | const hashedPassword = await hashPassword(password);
84 |
85 | await User.updateOne(
86 | { _id: user._id },
87 | { password: hashedPassword },
88 | { new: true }
89 | );
90 |
91 | await transporter.sendMail({
92 | from: process.env.EMAIL,
93 | to: user.email,
94 | subject: 'Password reset successufly',
95 | html: 'Password is successfuly reset',
96 | });
97 |
98 | // Delete token so it won't be used twice
99 | const deleteToken = await Token.deleteOne({ _id: token._id });
100 |
101 | if (!deleteToken) {
102 | res.status(403).end();
103 | }
104 |
105 | res
106 | .status(200)
107 | .json({ seccuess: true, message: 'Password is reset successfuly' });
108 | } else {
109 | res.status(400).json({ success: false, message: 'Bad request' });
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/components/signup.tsx:
--------------------------------------------------------------------------------
1 | import { Button, Flex, FormControl, FormErrorMessage, Heading, Input, Text, VStack } from '@chakra-ui/react';
2 | import { Dispatch, SetStateAction, useState } from 'react';
3 |
4 | interface SignUpProps {
5 | isSignInMode: boolean;
6 | setSignInMode: Dispatch