chore: fix test types

This commit is contained in:
Bereket Engida
2024-10-27 09:14:18 +03:00
parent a3d69b3e44
commit b36c03f83d
2 changed files with 21 additions and 11 deletions

View File

@@ -1,20 +1,26 @@
import { betterFetch } from "@better-fetch/fetch";
import { NextRequest, NextResponse } from "next/server";
import type { Session } from "./lib/auth-types";
import { client } from "./lib/auth-client";
export default async function authMiddleware(request: NextRequest) {
const { data: session } = await betterFetch<Session>(
"/api/auth/get-session",
{
baseURL: request.nextUrl.origin,
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: {
//get the cookie from the request
cookie: request.headers.get("cookie") || "",
},
},
);
});
if (!session) {
if (!session.data) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();