setting up files
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { hasEnvVars } from "../utils";
|
||||
import { isPublicPath, routes } from "@/lib/routes";
|
||||
import { getSupabaseEnv } from "@/lib/supabase/env";
|
||||
import { hasEnvVars } from "../utils";
|
||||
|
||||
export async function updateSession(request: NextRequest) {
|
||||
let supabaseResponse = NextResponse.next({
|
||||
@@ -50,15 +51,11 @@ export async function updateSession(request: NextRequest) {
|
||||
const { data } = await supabase.auth.getClaims();
|
||||
const user = data?.claims;
|
||||
|
||||
if (
|
||||
request.nextUrl.pathname !== "/" &&
|
||||
!user &&
|
||||
!request.nextUrl.pathname.startsWith("/login") &&
|
||||
!request.nextUrl.pathname.startsWith("/auth")
|
||||
) {
|
||||
// no user, potentially respond by redirecting the user to the login page
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
if (!user && !isPublicPath(pathname)) {
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = "/auth/login";
|
||||
url.pathname = routes.login;
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user