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,11 +1,11 @@
import findUserByUsername from '@/services/users/auth/findUserByUsername';
import Local from 'passport-local';
import { findUserByUsername } from '@/services/users/auth';
import ServerError from '../util/ServerError';
import { validatePassword } from './passwordFns';
const localStrat = new Local.Strategy(async (username, password, done) => {
try {
const user = await findUserByUsername(username);
const user = await findUserByUsername({ username });
if (!user) {
throw new ServerError('Username or password is incorrect.', 401);
}

View File

@@ -1,9 +1,10 @@
import { NextApiResponse } from 'next';
import { NextHandler } from 'next-connect';
import findUserById from '@/services/users/auth/findUserById';
import ServerError from '@/config/util/ServerError';
import { getLoginSession } from '../../auth/session';
import { UserExtendedNextApiRequest } from '../../auth/types';
import { findUserById } from '@/services/users/auth';
/** Get the current user from the session. Adds the user to the request object. */
const getCurrentUser = async (
@@ -12,7 +13,7 @@ const getCurrentUser = async (
next: NextHandler,
) => {
const session = await getLoginSession(req);
const user = await findUserById(session?.id);
const user = await findUserById({ userId: session?.id });
if (!user) {
throw new ServerError('User is not logged in.', 401);