first commit

This commit is contained in:
2024-11-24 23:30:44 +05:00
parent 92d9e90cd6
commit 7389de4c76
59 changed files with 6368 additions and 159 deletions

25
middleware.ts Normal file
View File

@ -0,0 +1,25 @@
import { betterFetch } from "@better-fetch/fetch";
import type { Session } from "better-auth/types";
import { type NextRequest, NextResponse } from "next/server";
export default async function authMiddleware(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") || "",
},
},
);
if (!session) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/devices", "/"],
};