Skip to content

Commit

Permalink
Merge pull request #131 from pedrolivaresanchez/pablogracia/fix-middl…
Browse files Browse the repository at this point in the history
…eware

Asegurarnos de que los redirects a /auth se hacen desde las url adecuadas
  • Loading branch information
patrickwebsdev authored Nov 7, 2024
2 parents 6d3b5ba + 9d73b7d commit a9ddc2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib/supabase/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ export async function updateSession(request: NextRequest) {
const {
data: { user },
} = await supabase.auth.getUser();
const url = request.nextUrl.clone();

if (!user && !request.nextUrl.pathname.startsWith('/login') && !request.nextUrl.pathname.startsWith('/auth')) {
// no user, potentially respond by redirecting the user to the login page
const url = request.nextUrl.clone();
url.pathname = '/login';
if (
!user &&
(request.nextUrl.pathname.startsWith('/ofertas') || request.nextUrl.pathname.startsWith('/solicitudes'))
) {
// no user, no access to their offers or requests. Redirect to log in

url.pathname = '/auth';
return NextResponse.redirect(url);
}

if (request.nextUrl.pathname === '/casos-activos') {
url.pathname = '/casos-activos/solicitudes';
return NextResponse.redirect(url);
}

Expand Down
File renamed without changes.

0 comments on commit a9ddc2c

Please sign in to comment.