W
Wasp4mo ago
NEROX

Save failed: there was a database error

App created with Mage, error when signup: [ Server!] PrismaClientValidationError: [ Server!] Invalid prisma.user.create() invocation in [ Server!] /home/rootall/apps/RoadmapBoard/.wasp/out/sdk/wasp/dist/auth/utils.js:78:24 [ Server!] [ Server!] 77 export async function createUser(providerId, serializedProviderData, userFields) { [ Server!] → 78 return prisma.user.create({ [ Server!] data: { [ Server!] auth: { [ Server!] create: { [ Server!] identities: { [ Server!] create: { [ Server!] providerName: "username", [ Server!] providerUserId: "test@gmail.com", [ Server!] providerData: "{\"hashedPassword\":\"$argon2imsdF+AAAAAAAAAAAAAAAAAAAAIY04DLNk\"}" [ Server!] } [ Server!] } [ Server!] } [ Server!] }, [ Server!] + email: String [ Server!] }, [ Server!] include: { [ Server!] auth: true [ Server!] } [ Server!] }) [ Server!] [ Server!] Argument email is missing. [ Server!] } [ Server ] POST /auth/username/signup 422 63.780 ms - 73 main.wasp:
app RoadmapBoard {
wasp: {
version: "^0.16.3"
},
title: "RoadmapBoard",
client: {
rootComponent: import { Layout } from "@src/Layout.jsx",
},
auth: {
userEntity: User,
methods: {
usernameAndPassword: {}
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/"
},
}
app RoadmapBoard {
wasp: {
version: "^0.16.3"
},
title: "RoadmapBoard",
client: {
rootComponent: import { Layout } from "@src/Layout.jsx",
},
auth: {
userEntity: User,
methods: {
usernameAndPassword: {}
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/"
},
}
What's missing?
5 Replies
kapa.ai
kapa.ai4mo ago
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the error message, it looks like your User entity is missing the required email field. When using the usernameAndPassword authentication method, your User entity needs to have certain fields defined. The error specifically states: Argument 'email' is missing in the Prisma client validation error, which indicates that the User entity schema doesn't have the email field that the auth system is trying to set during signup. Here's how you should update your User entity in your main.wasp file:
app RoadmapBoard {
wasp: {
version: "^0.16.3"
},
title: "RoadmapBoard",
client: {
rootComponent: import { Layout } from "@src/Layout.jsx",
},
auth: {
userEntity: User,
methods: {
usernameAndPassword: {}
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/"
},
}

entity User {=psl
id Int @id @default(autoincrement())
email String @unique
username String @unique
password String
psl=}
app RoadmapBoard {
wasp: {
version: "^0.16.3"
},
title: "RoadmapBoard",
client: {
rootComponent: import { Layout } from "@src/Layout.jsx",
},
auth: {
userEntity: User,
methods: {
usernameAndPassword: {}
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/"
},
}

entity User {=psl
id Int @id @default(autoincrement())
email String @unique
username String @unique
password String
psl=}
When using usernameAndPassword authentication, the User entity needs to have the following fields: - id (required) - email (required for the auth system) - username (required for username authentication) - password (required for password authentication) According to the documentation, these fields are necessary for the authentication system to work properly Username & Password Auth. If you're having issues with the fields being nullable, you can also try making them non-nullable by removing the ? if you have it in your schema, as mentioned in some GitHub issues Email and password can't be NOT NULL. Lucy: I noticed you're using Mage to create your app. Make sure to run wasp db migrate-dev after updating your schema to apply the changes to your database. I hope this helps! Let me know if you have any other questions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP4mo ago
Lucy: I noticed you're using Mage to...
Who is Lucy? @kapa.ai but the signup form doesn't show me the email field, just username and password
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I understand your confusion. When using the usernameAndPassword auth method, the default signup form only shows username and password fields, but the system still requires an email field in your User entity. There are a few ways to handle this: 1. Add the email field to the signup form: You can customize the signup form to include the email field by using the userSignupFields option. Here's how you can modify your main.wasp file:
app RoadmapBoard {
wasp: {
version: "^0.16.3"
},
title: "RoadmapBoard",
client: {
rootComponent: import { Layout } from "@src/Layout.jsx",
},
auth: {
userEntity: User,
methods: {
usernameAndPassword: {
userSignupFields: import { userSignupFields } from "@src/auth.js",
}
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/"
},
}
app RoadmapBoard {
wasp: {
version: "^0.16.3"
},
title: "RoadmapBoard",
client: {
rootComponent: import { Layout } from "@src/Layout.jsx",
},
auth: {
userEntity: User,
methods: {
usernameAndPassword: {
userSignupFields: import { userSignupFields } from "@src/auth.js",
}
},
onAuthFailedRedirectTo: "/login",
onAuthSucceededRedirectTo: "/"
},
}
Then create an auth.js file:
import { defineUserSignupFields } from 'wasp/server/auth'

export const userSignupFields = defineUserSignupFields({
email: (data) => {
if (!data.email) {
throw new Error('Email is required')
}
return data.email
}
})
import { defineUserSignupFields } from 'wasp/server/auth'

export const userSignupFields = defineUserSignupFields({
email: (data) => {
if (!data.email) {
throw new Error('Email is required')
}
return data.email
}
})
2. Create a custom signup form: If you want more control, you can create your own signup form and use Wasp's auth actions directly. This issue is documented in Wasp's GitHub issues, where users have requested the ability to customize the signup form with additional fields Allow customizing SignUp form with additional fields. The Wasp team has been working on improving this aspect of the framework, as mentioned in their documentation about customizing the signup process. Let me know if you need more specific guidance on implementing either of these approaches! Lucy: I noticed you're using Mage to create your app. Make sure to run wasp db migrate-dev after updating your schema to apply the changes to your database. Lucy: I noticed you're using Mage to create your app. Make sure to run wasp db migrate-dev after updating your schema to apply the changes to your database. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP4mo ago
Solved, was a stupid thing. The signup was set for username and password but in the User entity the email field was required
Filip
Filip4mo ago
Haha, who is Lucy indeed 😄 Ok, glad to hear it!

Did you find this page helpful?