mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
feat: add reset password functionality
This commit is contained in:
43
src/pages/users/reset-password.tsx
Normal file
43
src/pages/users/reset-password.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { setLoginSession } from '@/config/auth/session';
|
||||
import { verifyResetPasswordToken } from '@/config/jwt';
|
||||
import ServerError from '@/config/util/ServerError';
|
||||
import findUserById from '@/services/User/findUserById';
|
||||
|
||||
import { GetServerSideProps, NextApiResponse, NextPage } from 'next';
|
||||
|
||||
const TokenExpiredPage: NextPage = () => {
|
||||
return (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<div className="text-center">
|
||||
<h1 className="text-4xl font-bold">Token Expired</h1>
|
||||
<p className="text-lg">
|
||||
Your link to reset your password has expired or is invalid.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TokenExpiredPage;
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
try {
|
||||
const token = context.query.token as string | undefined;
|
||||
if (!token) {
|
||||
throw new ServerError('Token not provided', 400);
|
||||
}
|
||||
|
||||
const { id } = await verifyResetPasswordToken(token as string);
|
||||
|
||||
const user = await findUserById(id);
|
||||
if (!user) {
|
||||
throw new ServerError('User not found', 404);
|
||||
}
|
||||
|
||||
await setLoginSession(context.res as NextApiResponse, user);
|
||||
|
||||
return { redirect: { destination: '/account', permanent: false } };
|
||||
} catch (error) {
|
||||
return { props: {} };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user