mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Implement authentication using Passport.js
This commit is contained in:
18
config/auth/middleware/getCurrentUser.ts
Normal file
18
config/auth/middleware/getCurrentUser.ts
Normal 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;
|
||||
Reference in New Issue
Block a user