Sign up user with custom fields
(Using convex auth/Password)
Hey, so following the docs, I need custom fields for my users (who doesn't?), so I make a custom Password provider as specified for the password sign in/up function.
But now when I need to set up email verification, the custom Password provider is erroring, since it's not callable.
Code:
https://labs.convex.dev/auth/config/passwords#email-verification-setup
And the custom provider š¤·š»āāļø Does it only run on sign up? Is it okay to initialize values for new accounts here?
27 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Re: not callable error -- you either want to pass
verify: ResendOTP
in your CustomPassword.ts
file, or make CustomPassword.ts
export a function that accepts an argument like { verify: EmailConfig }
and passes that to the @convex-dev/auth
Password
Re: when is profile called -- https://labs.convex.dev/auth/api_reference/providers/Password#profile states "Called for every flow ("signUp", "signIn", "reset", "reset-verification" and "email-verification")."
Also take a look at https://labs.convex.dev/auth/setup/schema#customizing-the-users-table -- the fields returned by profile
should be automatically added to the entries in your users
tableproviders/Password - Convex Auth
Authentication library for your Convex backend
Customizing Schema - Convex Auth
Authentication library for your Convex backend
So it seems it isn't safe to do the initialization data of new accounts in profile, I guess I should do it in the front end when I call sign up.
And, thanks, I will try modifying the custo mpassword provider to accept an optional params object, I'll try and copy the default one.
So it seems it isn't safe to do the initialization data of new accounts in profile,Depends what you mean by safe -- it'll only modify the authenticated user (so not unsafe from a security perspective), but it'll run on things like sign in too, so unless you add a custom
createOrUpdateUser
callback, you could end up overwriting fields on existing usersI might have got it working (which then I can see if I'm clobbering my users), but, sending the verification email is failing:
What do I need to put for the SITE_URL? It's an expo app that serves to mobile and web, so it kind of has two? But I tried them and that didn't work.
I think you're hitting https://github.com/get-convex/convex-auth/issues/40 -- OTPs shouldn't really require a SITE_URL but they share code with magic links which leads to this error. I believe setting the
SITE_URL
to any value should unblock OTPs (e.g. npx convex env set SITE_URL http://localhost:3000
)GitHub
OTPs should not require SITE_URL Ā· Issue #40 Ā· get-convex/convex-au...
https://discord.com/channels/1019350475847499849/1263635045483155556 It's because we always generate the URL that includes the code param, even in the case of OTPs. This comes from the shape of...
Ah nice! Yes, I set the SITE_URL locally, that makes sense why it didn't work.
The next error is odd as well, it's showing an import for convex that doesn't exist, my project is in Documents, but it doesn't go Documents/convex, it's missing two directories in there...
All the imports are relative inside of of the convex folder
import { ResendOTP } from "./ResendOTP";
, the generated import in the api folder looks correct too.
Not sure about the import (it looks like it might be a metro thing), but can you change the
if (error)
block in ResendOTP
to console.error(error)
in addition to throwing? I'll also make this change to the templateOh nice! That's a much better error
Ah our example app actually prints the error but the code snippet in docs doesn't. I'll fix that
it wooooorkkssssss
š„³ thaaaank you
So I'm still having issues signing up, I get this error:
Which is because in my callback for creating a user, args doesn't have the data I sent in for sign up, only the email is coming through:
Even though my profile function does receive the params and returns them:
š
These are the params I get in profile:
Also, the user is added to the database with the accountType field correctly set.
show your user schema
Edit: Actually it still didn't work.
Hehe š
Another silly moment I guess.
I saw this
At which point I realized maybe I just need to return if the user was created successfully, which indeed fixed it.
I did find it confusing though since the logs didn't reflect that, and I expected this function to run on initial user creation š¤·š»āāļø
I'm sure there's a good reason for it though.
I also may have spoken too soon, I still need to check that everything worked, it just didn't error this time.
Ah, yeah, it didn't work, I'm not sure why it didn't error out that one time, but it is now, with the same error.
click on the log where it says error
take screenshot and past here
ok delete your user from table
all gone, it's all empty, including the auth sessions
and console.log args
right before the insert
oh
so you are using args.profile?
I'm a dummy one second.
let me try again
well we always do same mistakes haha
Okay it created account, I had altogether left out the initialization of the user, thinking it was somehow abstracted away since I didn't see it happenign earlier. But indeed it does actually run.
Now the second callback is not running, which is a new issue but would love your quick outlook on it.
what is the second callback?
It might not be necessary anymore, but, using the userId I need to add a record in the businesses table, I think I can do this in the first callback though, on user creation since I do have the userId... š¤
My guess is I can just move this to the first callback and use the userId I get back when I insert the user record.
just do it same time when you create the user
š
oh my god it's working. š Thank you so much