https://supabase.com/ logo
#help
Title
# help
j

jjj.westra

11/14/2021, 8:47 PM
Hi; Does anyone know how to set a users password with a service key; without logging in as that user?
s

silentworks

11/14/2021, 9:29 PM
You can't the user has to set their password themselves, so as you stated in your other message you can only send them a resetPassword email
j

jjj.westra

11/14/2021, 9:30 PM
Thanks; I thought so 🙂
I can also use the generateLink from the gotrue api
maybe to get a jwt token and set the password that way; from a db function
Nah; that wont work
c

chipilov

11/15/2021, 7:13 AM
I think you can reset their password with a direct connection to the DB (i.e. not with the supabase client but with a postgresql db client) - you just need to set the password field in the auth.users table and you need to make sure to hash it using bcrypt with a cost of 10 before storing it in the db (you actually need to use the default cost of the Go bcrypt library, which currently is 10)
btw, I think you can actually do it also via the supabase client if you expose the auth.users table through a view defined in the public schema...but this seems risky
j

jjj.westra

11/15/2021, 2:03 PM
Thanks for the bcrypt advise;
I was trying to do it from the database; but I didnt know how to encrypt the passwords
c

chipilov

11/15/2021, 2:06 PM
sure, no problem - supabase uses Netlify's GoTrue and you can see how it hashes the passwords before storing them here: https://github.com/netlify/gotrue/blob/b1d0dbaa0c8d1ac7d1d46bb865eb849d0e99e257/models/user.go#L190
j

jjj.westra

11/15/2021, 2:06 PM
By the way, I want to make an account manager for several of our products; thats the reason why i needed to set the password like this 😉
Thanks !