NextAuth error while using social login
Answered
Mugger Crocodile posted this in #help-forum
Mugger CrocodileOP
Error:
SignIn function
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror
[auth][cause]: TypeError: Cannot read properties of undefined (reading 'findUnique')
at getSessionAndUser (webpack-internal:///(middleware)/./node_modules/@auth/prisma-adapter/index.js:240:52)
at acc.<computed> (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/init.js:178:30)
at Module.session (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/actions/session.js:67:36)
at AuthInternal (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/index.js:47:77)
at async Auth (webpack-internal:///(middleware)/./node_modules/@auth/core/index.js:126:34)
at async handleAuth (webpack-internal:///(middleware)/./node_modules/next-auth/lib/index.js:134:29)
at async adapter (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/adapter.js:179:16)
at async C:\Users\Anurag\Desktop\Projects\airbnb\node_modules\next\dist\server\web\sandbox\sandbox.js:110:22
at async runWithTaggedErrors (C:\Users\Anurag\Desktop\Projects\airbnb\node_modules\next\dist\server\web\sandbox\sandbox.js:107:9)
at async DevServer.runMiddleware (C:\Users\Anurag\Desktop\Projects\airbnb\node_modules\next\dist\server\next-server.js:1062:24)
[auth][details]: {}
~<Button
outline
label="Continue with Github"
icon={FaGithub}
onClick={() => SignIn()}
></Button>
~SignIn function
"use server"
import { signIn } from "@/auth"
const SignIn = async () => {
await signIn("github")
}
export default SignIn
~Answered by Bigeye scad
Have you run db push or migrate
Just for confirmation check tables are in prisma studio
And have you created tables as per the docs
Like User , Session , Accounts
@Mugger Crocodile
Just for confirmation check tables are in prisma studio
And have you created tables as per the docs
Like User , Session , Accounts
@Mugger Crocodile
8 Replies
Mugger CrocodileOP
auth.ts
schema.prisma
i'm following the nextauth beta docs along with prisma's neon tech adapter docs..
import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import github from "next-auth/providers/github"
import { PrismaClient } from "@prisma/client"
import { PrismaNeon } from "@prisma/adapter-neon"
import { Pool } from "@neondatabase/serverless"
const neon = new Pool({
connectionString: process.env.AUTH_POSTGRES_PRISMA_URL,
})
const adapter = new PrismaNeon(neon)
const prisma = new PrismaClient({ adapter })
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [github],
})schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}i'm following the nextauth beta docs along with prisma's neon tech adapter docs..
Bigeye scad
Have you created tables in your database ?
@Mugger Crocodile
@Mugger Crocodile
Mugger CrocodileOP
Yes, The tables are visible in the neon dashboard
@Bigeye scad Have you created tables in your database ?
<@383593860128833536>
Mugger CrocodileOP
DATABASE_URL="postgresql://neondb_owner****************"
AUTH_POSTGRES_PRISMA_URL="postgresql://neondb_owner***********"~this is my .env btw
Bigeye scad
Have you run db push or migrate
Just for confirmation check tables are in prisma studio
And have you created tables as per the docs
Like User , Session , Accounts
@Mugger Crocodile
Just for confirmation check tables are in prisma studio
And have you created tables as per the docs
Like User , Session , Accounts
@Mugger Crocodile
Answer
@Bigeye scad Have you run db push or migrate
Just for confirmation check tables are in prisma studio
And have you created tables as per the docs
Like User , Session , Accounts
<@383593860128833536>
Mugger CrocodileOP
I tried to migrate, push and generate. and tried to sign up thru github. It creates a user on the database but throws the same error on website but throws this on cmd
I searched it on google and it said to run npx prisma generate which I already did
[auth][cause]: PrismaClientValidationError:
Invalid `prisma.account.create()` invocation:
{
data: {
access_token: "***************",
scope: "read:user,user:email",
token_type: "bearer",
providerAccountId: "60433065",
provider: "github",
type: "oauth",
userId: "***************",
+ user: {
+ create: UserCreateWithoutAccountsInput | UserUncheckedCreateWithoutAccountsInput,
+ connectOrCreate: UserCreateOrConnectWithoutAccountsInput,
+ connect: UserWhereUniqueInput
+ }
}
}
Argument `user` is missing.I searched it on google and it said to run npx prisma generate which I already did
Bigeye scad
is your database schema like this in the docs for postgres
view this docs : https://authjs.dev/getting-started/adapters/prisma
have you created user manually ?
view this docs : https://authjs.dev/getting-started/adapters/prisma
have you created user manually ?
Mugger CrocodileOP
yes..