Simple login is not working

Hello everyone, I am fighting with a generated code that doesnt’ work. Could you please help me?

What I would like to do: Create a login module to access a secure content.

What happens: After creating the database and the login form, and after input the right credentials, it redirects to login page again and again.

Any clue?: As the logs says, the cookies are not being saved.

Step by step:

  1. Create a blank project
  2. Create a prompt like “Create a dashboard page that shows after login”
  3. It creates the dashboard and login, and ask you to create the database and scripts. Everything runs perfectly.
  4. I need to create the user, and profile, and also remove teh “validate email” option from Supabase settings.
  5. After everything is done, I input right credentials and instead of redirecting to Dashboard, it redirects to Login agin.

It is driving me crazy.

Thank you

LOGS:

10:37:44.417Z [v0] CLIENT - Login attempt for: Pagofdad@asdf.com
10:37:44.419Z [v0] CLIENT - Creating browser client with: {“url”:“https://nokkkkkkk.supabase.co”,“hasAnonKey”:true}
10:37:44.420Z [v0] CLIENT - Browser client created successfully
10:37:44.420Z [v0] CLIENT - Supabase client created
10:37:45.353Z [v0] CLIENT - Login response: {“hasData”:true,“hasUser”:true,“userId”:“bcb58365-f517-483f-93b7-d2b3026598e7”,“hasSession”:true,“hasError”:false}
10:37:45.353Z [v0] CLIENT - Session created successfully: {“accessToken”:“eyJhbGIUzI1NiIs…”,“refreshToken”:“tqzlwgdx…”,“expiresAt”:1761057465}
10:37:45.354Z [v0] CLIENT - User verification after login: {“hasUser”:false}
10:37:45.354Z [v0] CLIENT - Document cookies:
10:37:45.354Z [v0] CLIENT - Redirecting to dashboard…
10:37:49.052Z [SERVER] [v0] MIDDLEWARE - updateSession called for path: /dashboard
10:37:49.052Z [SERVER] [v0] MIDDLEWARE - Request cookies: {“count”:0,“names”:}
10:37:49.054Z [SERVER] [v0] MIDDLEWARE - Calling supabase.auth.getUser()
10:37:49.055Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:49.056Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:49.056Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:49.056Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:49.056Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:49.056Z [SERVER] [v0] MIDDLEWARE - getUser result: {“hasUser”:false,“hasError”:true,“error”:“Auth session missing!”}
10:37:49.056Z [SERVER] [v0] MIDDLEWARE - Returning response
10:37:49.788Z [SERVER] [v0] DASHBOARD LAYOUT - Starting authentication check
10:37:49.788Z [SERVER] [v0] DASHBOARD LAYOUT - Available cookies: {“count”:0,“names”:,“supabaseCookies”:}
10:37:49.789Z [SERVER] [v0] DASHBOARD LAYOUT - Calling supabase.auth.getUser()
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - getAll called, returning: 0 cookies
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - getAll called, returning: 0 cookies
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - getAll called, returning: 0 cookies
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - getAll called, returning: 0 cookies
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - getAll called, returning: 0 cookies
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - getUser result: {“hasUser”:false,“hasError”:true,“error”:“Auth session missing!”}
10:37:49.790Z [SERVER] [v0] DASHBOARD LAYOUT - No user found, redirecting to login
10:37:53.148Z [SERVER] [v0] MIDDLEWARE - updateSession called for path: /login
10:37:53.148Z [SERVER] [v0] MIDDLEWARE - Request cookies: {“count”:0,“names”:}
10:37:53.149Z [SERVER] [v0] MIDDLEWARE - Calling supabase.auth.getUser()
10:37:53.150Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:53.150Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:53.150Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:53.151Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:53.151Z [SERVER] [v0] MIDDLEWARE - getAll called, returning: 0 cookies
10:37:53.151Z [SERVER] [v0] MIDDLEWARE - getUser result: {“hasUser”:false,“hasError”:true,“error”:“Auth session missing!”}
10:37:53.151Z [SERVER] [v0] MIDDLEWARE - Returning response

This sounds like a cookie/session management issue with your authentication flow. Here are a few things to check:

1. Supabase Configuration

  • Make sure your Supabase URL and anon key are correctly set in your environment variables
  • Verify that Row Level Security (RLS) policies are properly configured for your user table
  • Check that email confirmation is disabled in Supabase Auth settings if you’re not using it

2. Cookie Settings

  • Ensure your authentication cookies are being set with the correct domain and path
  • Check if you’re running on localhost vs a custom domain - this can affect cookie behavior
  • Verify that httpOnly and secure flags are appropriate for your environment

3. Middleware Configuration

  • Make sure your middleware is properly checking for authentication state
  • Verify that protected routes are correctly configured
  • Check that the middleware isn’t interfering with the login flow

4. Session Persistence

  • Confirm that the session is being properly stored after successful login
  • Check browser developer tools to see if cookies are actually being set
  • Verify that the session validation logic is working correctly

Let us know how you get on!