mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 20:37:44 +00:00
32 lines
737 B
TypeScript
32 lines
737 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { client } from "./lib/auth-client";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
// const { data: session } = await betterFetch<Session>(
|
|
// "/api/auth/get-session",
|
|
// {
|
|
// baseURL: request.nextUrl.origin,
|
|
// headers: {
|
|
// //get the cookie from the request
|
|
// cookie: request.headers.get("cookie") || "",
|
|
// },
|
|
// },
|
|
// );
|
|
const session = await client.getSession({
|
|
fetchOptions: {
|
|
headers: {
|
|
cookie: request.headers.get("cookie") || "",
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!session.data) {
|
|
return NextResponse.redirect(new URL("/", request.url));
|
|
}
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/dashboard"],
|
|
};
|