supanuxt-saas icon indicating copy to clipboard operation
supanuxt-saas copied to clipboard

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

Open Wivon opened this issue 1 year ago • 7 comments

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

Wivon avatar Aug 10 '24 10:08 Wivon

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?

JavascriptMick avatar Aug 14 '24 11:08 JavascriptMick

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.

Wivon avatar Aug 14 '24 11:08 Wivon

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 avatar Aug 27 '24 08:08 laurensiusadi

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.

laurensiusadi avatar Aug 28 '24 14:08 laurensiusadi

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

Wivon avatar Aug 28 '24 17:08 Wivon

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

JavascriptMick avatar Sep 25 '24 12:09 JavascriptMick

@JavascriptMick I believe that would work just fine

laurensiusadi avatar Dec 27 '24 03:12 laurensiusadi