Closed qqqllppp closed 4 months ago
This is expected. The ID for both user and session must be a string. Also see #1366
Hi @pilcrowOnPaper thanks for the response, I have now change my prisma.schema
& execution code to the below (change to comply with string type), and I am getting error on User
table now (so both User and Session table is empty).
schema.prisma
model User {
id String @id
email String @unique @db.String(320) // https://www.google.com/search?channel=fs&client=ubuntu-sn&q=max+email+string+length
hashedPassword String
createdAt DateTime @default(now())
session Session[]
}
model Session {
id String @id
userId String
expiresAt DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
execution code
import { generateId } from "lucia";
...
const hashedPassword = await new Argon2id().hash(
input.passwordObj.password,
);
const userId = generateId(15);
const data = await ctx.db.user.create({
data: {
id: userId,
email: input.email,
hashedPassword: hashedPassword,
},
});
const session = await lucia.createSession(userId, {});
ctx.res
.appendHeader(
"Set-Cookie",
lucia.createSessionCookie(session.id).serialize(),
)
.status(200)
.end();
Error:
Invalid `prisma.user.create()` invocation:
{
data: {
id: "r6qmicf115qh8zk",
~~~~~~~~~~~~~~~~~
email: "test123@gmail.com",
hashedPassword: "$argon2id$v=19$m=19456,t=2,p=1$qXcidGl7xstmRnft1p0/qw$kwXT3rpPjvZzwbnZorQyC4eqmBtmjGdLZiSLW1zCheM"
}
}
Invalid value for argument `id`: invalid digit found in string. Expected big integer String.
❌ tRPC failed on auth.signUp: PrismaClientValidationError:
Invalid `prisma.user.create()` invocation:
{
data: {
id: "r6qmicf115qh8zk",
~~~~~~~~~~~~~~~~~
email: "test123@gmail.com",
hashedPassword: "$argon2id$v=19$m=19456,t=2,p=1$qXcidGl7xstmRnft1p0/qw$kwXT3rpPjvZzwbnZorQyC4eqmBtmjGdLZiSLW1zCheM"
}
}
Invalid value for argument `id`: invalid digit found in string. Expected big integer String.
Note: I am using const userId = generateId(15);
for id
now.
Did you actually push the changes?
I did push the db changes, but I had to restart my dev app as well for the changes to apply xD Thanks a bunch!
If the application is still running prisma can´t update the node modules with the new schema.prisma ... that was probably the reason for the issue.
Package
@lucia-auth/adapter-prisma
Describe the bug
I am new to lucia, I am trying to sign up a new user but I keep getting an error on the "session" part.
I am using Prisma with Cockroach DB and TRPC with NextJS.
My
schema.prisma
looks like:The execution code looks like that:
The error occurs on this line:
Whenever I sign up a new user, the
User
table is populated but theSession
table remains empty due to the error.Here is an example of data in
User
table: