mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
19 lines
552 B
TypeScript
19 lines
552 B
TypeScript
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;
|