Implement authentication using Passport.js

This commit is contained in:
Aaron William Po
2023-02-05 19:27:19 -05:00
parent 86f6f9abc5
commit 087a1a4513
26 changed files with 2073 additions and 412 deletions

View File

@@ -0,0 +1,18 @@
import { NextApiResponse } from 'next';
import { NextHandler } from 'next-connect';
import { getLoginSession } from '../session';
import { ExtendedNextApiRequest } from '../types';
/** Get the current user from the session. Adds the user to the request object. */
const getCurrentUser = async (
req: ExtendedNextApiRequest,
res: NextApiResponse,
next: NextHandler,
) => {
const session = await getLoginSession(req);
const user = { id: session.id, username: session.username };
req.user = user;
next();
};
export default getCurrentUser;