Additional fields in User Table not retrieved after dbAuth setup

I had a User table with additional fields: id, email, firstname, lastname, create_date, etc.
Loved the idea to db authentication, and setup the dbAuth.
I added the hashedPassword and salt fields to the db and to the model, and then I scaffold the user model (with force).
After doing so, all the other fields in the db were not retrieved. The only one that were retrieved were those that were defined in the auth.js file.
I tried also to change the db.user.findMany() to include the 'select' option for the missing fields (as described in Prisma docs), but got error message like:

api | Invalid `prisma.user.findMany()` invocation:
api | 
api | {
api |   select: {
api | ?   id?: true,
api | ?   email?: true,
api | ?   hashedPassword?: true,
api | ?   salt?: true,
api |     create_date: true
api |     ~~~~~~~~~~~
api |   }
api | }
api | 
api | 
api | Unknown field `create_date` for select statement on model User. Available options are listed in green.

I also tried to add the additional fields to the 'api\src\functions\auth.js', like:

authFields: {
      id: 'id',
      username: 'email',
      hashedPassword: 'hashedPassword',
      salt: 'salt',
      create_by: 'create_by',
      create_date: 'create_date',

that did not help as well.

When I used the db.user.findMany(), and logged the QUERY for Prisma, to log the SQL statement, it did not include any of the additional fields, although they are included in the model:

"SELECT \"gvg\".\"users\".\"id\", 
FROM \"gvg\".\"users\"
WHERE \"gvg\".\"users\".\"id\" = $1 

Prisma Studio does retrieve the fields correctly.

Any suggestions?

So, after some trial and error, I found the solution.
If it was mentioned in the documentation that would have save so much time.

  • after every change in the model, you should recreate the artifacts by using yarn rw prisma generate.
  • this regenerate the file .redwood\schema.graphql, and more importantly the file node_modules\api\types\graphql.d.ts, which hold alll the type definitions for the input types for the forms and the create types.

Regenerating these files, and restarting the app, had resolved all the issues.

1 Like