Hi; Does anyone know how to set a users password w...
# help
j
Hi; Does anyone know how to set a users password with a service key; without logging in as that user?
s
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
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
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
Thanks for the bcrypt advise;
I was trying to do it from the database; but I didnt know how to encrypt the passwords
c
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
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 !