Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { fromNodeHeaders } from "better-auth/node";
- import { NextFunction, Request, Response } from "express";
- import { auth } from "../config/auth";
- const authMiddleware = async (
- req: Request,
- res: Response,
- next: NextFunction
- ) => {
- const session = await auth.api.getSession({
- headers: fromNodeHeaders(req.headers),
- });
- console.log(fromNodeHeaders(req.headers))
- if (!session) {
- res.status(400).json({
- message: "unauthorized",
- });
- return;
- }
- req.user = session.user;
- next();
- };
- export default authMiddleware;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement