-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
33 lines (30 loc) · 983 Bytes
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { NextRequest, NextResponse } from "next/server";
import {
COLLECTION_NAME_PROFILE,
COOKIE_NAME_USER_LOGIN,
} from "./lib/constants";
import getSession from "./lib/session";
import { collection, getDocs, query, where } from "firebase/firestore";
import { firestore } from "./config/firebase/firebase";
export async function middleware(request: NextRequest) {
console.log(request.nextUrl.pathname);
if (
request.nextUrl.pathname === "/" ||
request.nextUrl.pathname === "/create-profile" ||
request.nextUrl.pathname === "/profile" ||
request.nextUrl.pathname.includes("/tweet")
) {
const session = await getSession();
const id = session.id;
if (!id) {
return Response.redirect(new URL("/log-in", request.url));
}
}
/*
if (!(await hasProfile(id))) {
return Response.redirect(new URL("/create-profile", request.url));
}*/
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};