JavascriptMick / supanuxt-saas

Simple boilerplate for SAAS. Nuxt3, Supabase, OAuth, Prisma, TRPC, Pinia, Stripe, Tailwind, OpenAI
https://nuxt3-saas-boilerplate.netlify.app/
MIT License
413 stars 57 forks source link

signup, dashboard & account mgmnt throw "UNAUTHORIZED" (no infos found) #21

Open Wivon opened 2 months ago

Wivon commented 2 months ago

What's happening:

After signing in, or signing up, some data is undefined (e.g. activeMembership, accountStore). Nothing is populated in the DB (tables "account" and "user" are still empty after creating several accounts). This breaks the whole app: dashboard page is not populating since activeMembership isn't defined, same occurs for account page.

Error msg

TRPCError: UNAUTHORIZED
    at <anonymous> (/Users/lilian/Code-local/vecting-supanuxt/server/trpc/trpc.ts:39:11)
    at callRecursive (file:///Users/lilian/Code-local/vecting-supanuxt/node_modules/@trpc/server/dist/index.mjs:451:38)
    at resolve (file:///Users/lilian/Code-local/vecting-supanuxt/node_modules/@trpc/server/dist/index.mjs:481:30)
    at callProcedure (file:///Users/lilian/Code-local/vecting-supanuxt/node_modules/@trpc/server/dist/config-d5fdbd39.mjs:155:12)
    at inputToProcedureCall (file:///Users/lilian/Code-local/vecting-supanuxt/node_modules/@trpc/server/dist/resolveHTTPResponse-2fc435bb.mjs:46:28)
    at file:///Users/lilian/Code-local/vecting-supanuxt/node_modules/@trpc/server/dist/resolveHTTPResponse-2fc435bb.mjs:169:51
    at Array.map (<anonymous>)
    at resolveHTTPResponse (file:///Users/lilian/Code-local/vecting-supanuxt/node_modules/@trpc/server/dist/resolveHTTPResponse-2fc435bb.mjs:169:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at <anonymous> (/Users/lilian/Code-local/vecting-supanuxt/node_modules/trpc-nuxt/dist/index.mjs:49:26) {
  code: 'UNAUTHORIZED',
  [cause]: undefined
}

-> often with message: 'no user or active account information was found'

screenshots

Screenshot 2024-08-10 at 12 11 37 Screenshot 2024-08-10 at 12 12 22

JavascriptMick commented 2 months ago

hi @Wivon Sorry to hear you are having trouble. TBH smells like a setup/config issue rather than a code issue.

Maybe re-check the steps in the readme under the Supabase heading

What OAuth provider did you choose? is localhost set up as a redirect URL? does your login go through the OAuth Handshake?

Wivon commented 2 months ago

Hi @JavascriptMick I checked the setup before sending the issues, but unfortunately didn't work as well. I tested using Google OAuth and email. And yes the login. I added localhost as redirect URL in supabase and allowed this URL too in Google OAuth settings. Yes it seems like the login process is working fine, the problems starts after login.

laurensiusadi commented 2 months ago

Hi, I'm facing the same issue. Using plain email and password auth. From what I understand, AuthService.createUser() is not getting called, because somehow the server/middleware/authContext.ts is not getting called after sign up.

laurensiusadi commented 2 months ago

https://github.com/JavascriptMick/supanuxt-saas/blob/460c859ab3012fa0a3bf267a6cb6e4cf03c17784/server/middleware/authContext.ts#L25

@Wivon I found the fix. You need to change 'sb-access-token' to 'sb-supabaseProjectId-auth-token'. I found out from checking what cookie name Supabase is storing on the browser, and it works! I have all data populated on the tables now.

Wivon commented 2 months ago

Thanks for the help, I switched to SuperSaaS boilerplate (by microbot) but that's good to know :)

JavascriptMick commented 1 month ago

thanks @laurensiusadi nice spot. wierd though, cookie on my live site is still sb-access-token. I wonder if it would be saver to just not check for the presence of the specific cookie and let if fall through to

const user = await serverSupabaseUser(event);

which will probably just fail if cookies were not present anyway