dbAuth+WebAuthn stops working when adding User scaffolding

dbAuth with WebAuthn work great for me by following the steps in the docs:

  1. yarn create redwood-app my-app
  2. cd my-app
  3. add User and UserCredentials models to api/db/prisma.schema (as specified in the link above under “Schema Updates”)
  4. yarn rw prisma migrate dev
  5. yarn rw setup auth dbAuth (‘y’ to add WebAuthn)
  6. yarn rw g dbAuth --webauthn
  7. yarn rw dev

The above works beautifully for dbAuth+WebAuthn. But when I try to create a User scaffold, the whole dbAuth system breaks.

  1. yarn rw g scaffold admin/user

I get the following error:
Schema loading failed. Unknown type: "UserCredential"

This error tells me that I need to generate SDL or scaffolding for UserCredential too. But when I try to do this:

  1. yarn rw g scaffold admin/usercredential
    or
    yarn rw g sdl UserCredential

I get the following error:
Cannot read properties of undefined (reading 'replace')

The problem I run into with dbAuth at this point is when I logOut of a page, the session appears to clear, but if I refresh the page, the state is not maintained and the user appears to be logged in again (the session doesn’t appear to get cleared). This only happens when I try to create the User scaffolding.

I followed the instructions on troubleshooting generators and commented out the following lines in api/db/prisma.schema:

model User {
...
  //credentials         UserCredential[]
}

model UserCredential {
...
  //userId     Int
  //user       User    @relation(fields: [userId], references: [id])
...
}

then re-ran the User scaffolding and dbAuth+WebAuthn work perfectly again! However, if I then uncomment the above prisma.schema lines to create the relationship again and re-run the scaffolding (even with the --force --no-tests flags), dbAuth stops working again. Even though I can get it to work by commenting out the User and UserCredential relationship, I’m pretty sure this relationship is important right?

Can anyone help with how I can create a User scaffold while maintaining the UserCredential to User relationship and have dbAuth+WebAuthn work properly?

1 Like