mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-07 04:19:22 +00:00
23 lines
524 B
TypeScript
23 lines
524 B
TypeScript
import { client } from "@/lib/auth-client";
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export default async function authMiddleware(request: NextRequest) {
|
|
const { data: session } = await client.getSession({
|
|
fetchOptions: {
|
|
headers: {
|
|
//get the cookie from the request
|
|
cookie: request.headers.get("cookie") || "",
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!session) {
|
|
return NextResponse.redirect(new URL("/", request.url));
|
|
}
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/dashboard"],
|
|
};
|