Google Login with PrismaAdapter always throws this error!"[next-auth][error][adapter_error_getUserByAccount] https://next-auth.js.org/errors#adapter_error_getuserbyaccount Cannot read properties of undefined (reading 'account') " #8337
Unanswered
Dharmavineta
asked this question in
Help
Replies: 3 comments
-
Have you found a solution for this issue yet? As I am also encountering the same issue. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I fixed this issue by deleting the accounts model on db. |
Beta Was this translation helpful? Give feedback.
0 replies
-
You may need to regenerate your prisma schema e.g. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question 💬
I've Next-auth Setup with GoogleProvider. I've created route.ts in app/api/auth/[...nextauth], and have configured handler there. In the handler I'm importing authOptions function which has the details of the providers,strategy and etc. I'm able to login and get the login details but when I include the adapter field in the authOptions, it always thows error and the login doesn't work at all.
I've tried all the solutions but to no avail. I'm new to next.js as such, I feel I'm missing something trivial.
When I login with the prisma adapter, I'm taken tohttp://localhost:3000/api/auth/signin?error=Callback and the page shows a button with the prompt "Please use other account to login"
I've setup the prisma schema as given in the documentation and I've migrated the tables to the database. The database connection works perfectly.
Also my intention to use adapter is to get the id of the user from the posgres table so that i can append it to the session.
This is the complete error
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR] https://next-auth.js.org/errors#oauth_callback_handler_error Cannot read properties of undefined (reading 'account') TypeError: Cannot read properties of undefined (reading 'account') at getUserByAccount (webpack-internal:///(rsc)/./node_modules/@next-auth/prisma-adapter/dist/index.js:222:37) at _callee2$ (webpack-internal:///(rsc)/./node_modules/next-auth/core/errors.js:301:43) at tryCatch (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/regeneratorRuntime.js:36:25) at Generator.eval (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/regeneratorRuntime.js:123:30) at Generator.eval [as next] (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/regeneratorRuntime.js:64:29) at asyncGeneratorStep (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/asyncToGenerator.js:4:28) at _next (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:17) at eval (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:13) at new Promise (<anonymous>) at eval (webpack-internal:///(rsc)/./node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:16) at Object.callback (webpack-internal:///(rsc)/./node_modules/next-auth/core/routes/callback.js:42:49) at async AuthHandler (webpack-internal:///(rsc)/./node_modules/next-auth/core/index.js:202:38) at async NextAuthRouteHandler (webpack-internal:///(rsc)/./node_modules/next-auth/next/index.js:50:30) at async NextAuth._args$ (webpack-internal:///(rsc)/./node_modules/next-auth/next/index.js:84:24) at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37) { name: 'GetUserByAccountError', code: undefined }
This is my authOptions function
`import NextAuth, { NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { prisma } from "./db";
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
session: {
strategy: "jwt",
},
// callbacks: {
// jwt: async ({ token }) => {},
// session: async ({ token }) => {},
// },
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
}),
],
secret: process.env.NEXT_AUTH_SECRET,
};
`
It works if I remove the adapter field and don't mention the callbacks.
This error constantly appears the moment I start using the Prismaadapter. I don't know if it's adapter problem or if I'm missing Something. Please HELP!!
How to reproduce ☕️
.
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Beta Was this translation helpful? Give feedback.
All reactions