Update user auth services

This commit is contained in:
Aaron William Po
2023-12-17 13:39:50 -05:00
parent 70a168df92
commit bffa28b93d
31 changed files with 700 additions and 552 deletions

View File

@@ -1,5 +1,5 @@
import useMediaQuery from '@/hooks/utilities/useMediaQuery';
import findUserById from '@/services/users/auth/findUserById';
import GetUserSchema from '@/services/users/auth/schema/GetUserSchema';
import Head from 'next/head';
@@ -7,6 +7,7 @@ import { FC } from 'react';
import { z } from 'zod';
import withPageAuthRequired from '@/util/withPageAuthRequired';
import UserHeader from '@/components/UserPage/UserHeader';
import { findUserById } from '@/services/users/auth';
interface UserInfoPageProps {
user: z.infer<typeof GetUserSchema>;
@@ -39,7 +40,7 @@ export default UserInfoPage;
export const getServerSideProps = withPageAuthRequired<UserInfoPageProps>(
async (context) => {
const { id } = context.params!;
const user = await findUserById(id as string);
const user = await findUserById({ userId: id as string });
return user
? { props: { user: JSON.parse(JSON.stringify(user)) } }
: { notFound: true };

View File

@@ -1,7 +1,7 @@
import { setLoginSession } from '@/config/auth/session';
import { verifyResetPasswordToken } from '@/config/jwt';
import ServerError from '@/config/util/ServerError';
import findUserById from '@/services/users/auth/findUserById';
import { findUserById } from '@/services/users/auth';
import { GetServerSideProps, NextApiResponse, NextPage } from 'next';
@@ -29,14 +29,14 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const { id } = await verifyResetPasswordToken(token as string);
const user = await findUserById(id);
const user = await findUserById({ userId: id as string });
if (!user) {
throw new ServerError('User not found', 404);
}
await setLoginSession(context.res as NextApiResponse, user);
return { redirect: { destination: '/account', permanent: false } };
return { redirect: { destination: '/users/account', permanent: false } };
} catch (error) {
return { props: {} };
}