Update next-connect, begin work on cloud img upload

This commit is contained in:
Aaron William Po
2023-02-09 23:58:03 -05:00
parent 0fb013e250
commit 45cc10a009
17 changed files with 1616 additions and 121 deletions

View File

@@ -0,0 +1,25 @@
import { NextApiResponse } from 'next';
import { NextHandler } from 'next-connect';
import findUserById from '@/services/User/findUserById';
import ServerError from '@/config/util/ServerError';
import { getLoginSession } from '../../auth/session';
import { UserExtendedNextApiRequest } from '../../auth/types';
/** Get the current user from the session. Adds the user to the request object. */
const getCurrentUser = async (
req: UserExtendedNextApiRequest,
res: NextApiResponse,
next: NextHandler,
) => {
const session = await getLoginSession(req);
const user = await findUserById(session?.id);
if (!user) {
throw new ServerError('Could not get user.', 401);
}
req.user = user;
return next();
};
export default getCurrentUser;