nhost / hasura-backend-plus

🔑Auth and 📦Storage for Hasura. The quickest way to get Auth and Storage working for your next app based on Hasura.
https://nhost.github.io/hasura-backend-plus/
MIT License
1.17k stars 187 forks source link

Catching unique REGISTRATION_CUSTOM_FIELDS #593

Closed joshmedeski closed 3 years ago

joshmedeski commented 3 years ago

I'm building an app that uses the username custom registration field. I've added a unique constraint on the database but get a general 500 if that unique constraint fails.

hasura-backend-plus_1  | Error inserting user account
hasura-backend-plus_1  | Error: Could not perform request
hasura-backend-plus_1  |     at Object.request (/app/dist/shared/request.js:25:15)
hasura-backend-plus_1  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
hasura-backend-plus_1  |     at async registerAccount (/app/dist/routes/auth/register.js:50:20)

I'd like to hasura-backend-plus to return an appropriate message like this:

username is already taken

joshmedeski commented 3 years ago

@elitan @komninoschat let me know if you have any suggestions on how to code this. I'm thinking of allowing any unique constraint errors to output an appropriate error message like this:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "username already exists."
}
elitan commented 3 years ago

Duplicate of https://github.com/nhost/hasura-backend-plus/issues/426

The server will return 500 and logs will be available for HBP.