mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Update user auth services
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user