Running custom server code when changing password

Hi all, I'm evaluating Supabase for use in an application that employs end-to-end-encryption. A user's data in the database is encrypted with a key derived from their password, so when they change the password, the server needs to re-encrypt their data with the new password, and abort the change if the re-encryption fails for whatever reason. Is this something that Supabase supports?
3 Replies
dannyh
dannyh2y ago
Pretty sure you can't even see a user's password at all. You can definitely access their encrypted password, and use that as a key, so if you're OK with that, then I'm pretty sure it would work. The flow I would do is to set up a trigger on the auth table that Supabase provides for you. The trigger would run on before update and call a Supabase edge function which decrypts with the previous password, and re-encrypts with the new password. If it fails, you can just set the encrypted password back to the old one.
garyaustin
garyaustin2y ago
The password is passed in the body in plain text but encrypted in transit by https. Then the gotrue server gets the plain text password and hashes it using bcrypt to store in the database. The only "hook" you have in that process is the database insert and it is already hashed to be stored in the database.
! Roda-Rora !
! Roda-Rora !OP2y ago
I see. Since the key is derived from the plaintext password on the client side and used to encrypt data on the client device I don't think this works for me. I suppose I need to avoid calling Supabase directly from the client then.

Did you find this page helpful?