I have a very stupid question: Is there
I have a very stupid question: Is there a way to programmatically create a user with password in convex?
17 Replies
Can you give a little more context on your goal, might help
(I'd also say this isn't a stupid question at all imo)
Sure, let me elaborate: I have a controlled / closed environment, meaning it's running on-premise. I want to use convex with convex-auth for authentication. Now I have set-up convex-saas locally with the password provider, but I have no way to create a user programmatically. Neither the tutorial for convex-auth nor any other source I found mentions how to create users with their passwords. I can let them sign up, which would probably work, but would not be viable for my solution since people would receive their logins by an administrator (me basically). There's no need for additional security measures or self-service in terms of resetting the passwords or emails.
Hope that's enough context, let me know if I should elaborate on any part 🙏
It would take some working around. Have you considered having "sending them their login" being just instructions to sign up with their email address, but you check to ensure the email address is on a list of approved signup emails? Or do you specifically not want folks creating their own passwords and having actual auth
You could run the check via
createOrUpdateUser()
, and do any other mutations you might want for admin purposes https://labs.convex.dev/auth/advanced#controlling-user-creation-and-account-linking-behaviorAdvanced: Details - Convex Auth
Authentication library for your Convex backend
Since it's a air-gapped environment, there's no way to send mails or access the internet. The only way to access the system is through https on this network. I specifically don't want users to create their own passwords yes 😆
Ah I see. Hmm
I tried using insert into the collection but this way I don't get a password.
You could try calling the signin action server side, wrap it in your own function for provisioning users
eg.,
ctx.runAction(api.auth.signIn, { ...params? })
you'd have to figure out the params to send. But if you have no email verification enabled, that might workThat's a great start, I'll dig into this 🙏 . Thank you very much
Please update if you land on a solution! Might be helpful for others
I tried running:
But this doesn't create anything and silently fails 😄
No errors in the convex logs?
I'd start taking a look at the source to see what's expected: https://github.com/get-convex/convex-auth/blob/2f77702b0e42fa705dfe2af623494682e6a21b49/src/server/implementation/index.ts#L392
GitHub
convex-auth/src/server/implementation/index.ts at 2f77702b0e42fa705...
Library for built-in auth. Contribute to get-convex/convex-auth development by creating an account on GitHub.
That's the signIn action
Oh, and turn on verbose logging as well
that might fix the silent failure
(or fix the silence, that is, maybe)
I looked up the function signature and found that my parameters would match. I then signed up through the frontend to see what's happening in comparison to my action. So the arguments should be good as far as I see. I'm gonna look how to turn on verbose logging then 😄
Ah, getting errors ⚠️ thanks for the hint
That was it ...
You will never guess what the error was 😆
It's "signUp" not "signup"
This one works flawlessly 🎉 . Thank you a thousand times @erquhart ! Do you have a patron / coffee page I can spend some coins on?
Nope, this is just Convex community helping each other out ❤️
Glad it worked!
Not without your help 🙏 . This was my last blocker I believe. Thank you a lot!