Update middleware.ts

This commit is contained in:
vergiLgood1 2025-04-05 09:27:58 +07:00
parent 5d3665807e
commit 2ee73acfe7
1 changed files with 5 additions and 0 deletions

View File

@ -39,6 +39,10 @@ export const updateSession = async (request: NextRequest) => {
// https://supabase.com/docs/guides/auth/server-side/nextjs
const user = await supabase.auth.getUser();
if (request.nextUrl.pathname === "/" && user.error) {
return NextResponse.redirect(new URL("/sign-in", request.url));
}
// protected routes
if (request.nextUrl.pathname.startsWith("/dashboard") && user.error) {
return NextResponse.redirect(new URL("/sign-in", request.url));
@ -48,6 +52,7 @@ export const updateSession = async (request: NextRequest) => {
return NextResponse.redirect(new URL("/dashboard", request.url));
}
return response;
} catch (e) {
// If you are here, a Supabase client could not be created!