vercel / platforms

A full-stack Next.js app with multi-tenancy and custom domain support. Built with Next.js App Router and the Vercel Domains API.
https://app.vercel.pub
5.73k stars 764 forks source link

Github login not working #437

Closed Mbensler closed 1 month ago

Mbensler commented 1 month ago

I have deployed the template and setup everything.

When going to my domain at app.mydomain.com/login i can login with Github.

When pressing login it shows me the "Authorize Github app" page. I press authorize, and then i am redirected back to app.mydomain.com/login and it still just says "Login with Github".

If i press login again it just loads for a second and then same page. Login with Github.

I tried locally and same thing happens but i get this error:

Query: select "accounts"."userId", "accounts"."type", "accounts"."provider", "accounts"."providerAccountId", "accounts"."refresh_token", "accounts"."refresh_token_expires_in", "accounts"."access_token", "accounts"."expires_at", "accounts"."token_type", "accounts"."scope", "accounts"."id_token", "accounts"."session_state", "accounts"."oauth_token_secret", "accounts"."oauth_token", "users"."id", "users"."name", "users"."username", "users"."gh_username", "users"."email", "users"."emailVerified", "users"."image", "users"."createdAt", "users"."updatedAt" from "accounts" inner join "users" on "accounts"."userId" = "users"."id" where ("accounts"."provider" = $1 and "accounts"."providerAccountId" = $2) -- params: ["github", "3165204"]
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR] 
https://next-auth.js.org/errors#oauth_callback_handler_error Cannot set property error of #<ErrorEvent> which has only a getter {
  message: 'Cannot set property error of #<ErrorEvent> which has only a getter',
  stack: 'TypeError: Cannot set property error of #<ErrorEvent> which has only a getter\n' +
    '    at formatError (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.7_next@14.0.2_react-dom@18.3.1_react@18.3.1/node_modules/next-auth/utils/logger.js:42:17)\n' +
    '    at Object.error (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.7_next@14.0.2_react-dom@18.3.1_react@18.3.1/node_modules/next-auth/utils/logger.js:52:20)\n' +
    '    at _callee2$ (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.7_next@14.0.2_react-dom@18.3.1_react@18.3.1/node_modules/next-auth/core/errors.js:307:36)\n' +
    '    at tryCatch (webpack-internal:///(rsc)/./node_modules/.pnpm/@babel+runtime@7.24.7/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:36:24)\n' +
    '    at Generator.eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@babel+runtime@7.24.7/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:123:25)\n' +
    '    at Generator.eval [as throw] (webpack-internal:///(rsc)/./node_modules/.pnpm/@babel+runtime@7.24.7/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:64:29)\n' +
    '    at asyncGeneratorStep (webpack-internal:///(rsc)/./node_modules/.pnpm/@babel+runtime@7.24.7/node_modules/@babel/runtime/helpers/asyncToGenerator.js:4:21)\n' +
    '    at _throw (webpack-internal:///(rsc)/./node_modules/.pnpm/@babel+runtime@7.24.7/node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:17)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)',
  name: 'TypeError'
}

Query: select "accounts"."userId", "accounts"."type", "accounts"."provider", "accounts"."providerAccountId", "accounts"."refresh_token", "accounts"."refresh_token_expires_in", "accounts"."access_token", "accounts"."expires_at", "accounts"."token_type", "accounts"."scope", "accounts"."id_token", "accounts"."session_state", "accounts"."oauth_token_secret", "accounts"."oauth_token", "users"."id", "users"."name", "users"."username", "users"."gh_username", "users"."email", "users"."emailVerified", "users"."image", "users"."createdAt", "users"."updatedAt" from "accounts" inner join "users" on "accounts"."userId" = "users"."id" where ("accounts"."provider" = $1 and "accounts"."providerAccountId" = $2) -- params: ["github", "3165204"]
Query: select "accounts"."userId", "accounts"."type", "accounts"."provider", "accounts"."providerAccountId", "accounts"."refresh_token", "accounts"."refresh_token_expires_in", "accounts"."access_token", "accounts"."expires_at", "accounts"."token_type", "accounts"."scope", "accounts"."id_token", "accounts"."session_state", "accounts"."oauth_token_secret", "accounts"."oauth_token", "users"."id", "users"."name", "users"."username", "users"."gh_username", "users"."email", "users"."emailVerified", "users"."image", "users"."createdAt", "users"."updatedAt" from "accounts" inner join "users" on "accounts"."userId" = "users"."id" where ("accounts"."provider" = $1 and "accounts"."providerAccountId" = $2) -- params: ["github", "3165204"]
Query: insert into "users" ("id", "name", "username", "gh_username", "email", "emailVerified", "image", "createdAt", "updatedAt") values ($1, $2, default, $3, default, $4, $5, default, $6) returning "id", "name", "username", "gh_username", "email", "emailVerified", "image", "createdAt", "updatedAt" -- params: ["cdb3sottpnfpyknxcji246c8", "MyName", "Mbensler", null, "https://avatars.githubusercontent.com/u/3165204?v=4", "2024-10-21T19:27:24.711Z"]
[next-auth][error][adapter_error_createUser] 
https://next-auth.js.org/errors#adapter_error_createuser null value in column "email" of relation "users" violates not-null constraint {
  message: 'null value in column "email" of relation "users" violates not-null constraint',
  stack: 'error: null value in column "email" of relation "users" violates not-null constraint\n' +
    '    at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@neondatabase+serverless@0.7.2/node_modules/@neondatabase/serverless/index.mjs:4141:25)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n' +
    '    at async VercelPgPreparedQuery.execute (webpack-internal:///(rsc)/./node_modules/.pnpm/drizzle-orm@0.31.2_@types+react@18.3.3_@vercel+postgres@0.8.0_pg@8.12.0_react@18.3.1/node_modules/drizzle-orm/vercel-postgres/session.js:52:26)',
  name: 'error'
}
Mbensler commented 1 month ago

Fixed by adding email scope in the Github App.