Update middleware.ts
This commit is contained in:
parent
5d3665807e
commit
2ee73acfe7
|
@ -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!
|
||||
|
|
Loading…
Reference in New Issue