Resend, Email verification/login not working?
Everythign seems to be working but after i click the link in the email it opens the site/app in a browser on the login page but you not logged in.
- it did create the user and user features records.
- authAccounts has record, authVerificationCodes has record
What am I missing and why was the
afterUserCreatedOrUpdated()
callback function not called?15 Replies
This is either undocumented or poorly documented, but I believe the query parameter needs to be
code
as opposed to token
https://github.com/get-convex/convex-auth/blob/10d5fd225b9b3898dd81d6271d5b926b85bda9c8/src/nextjs/server/request.ts#L29
is what would exchange that code for valid auth
GitHub
convex-auth/src/nextjs/server/request.ts at 10d5fd225b9b3898dd81d62...
Library for built-in auth. Contribute to get-convex/convex-auth development by creating an account on GitHub.
So concretely changing
to
might get things working
makes sense. that code is from https://labs.convex.dev/auth/config/email but could be wrong. let me give it a shot.
Magic Links - Convex Auth
Authentication library for your Convex backend
with your change:
added email param (for the hell of it). I don't think thats it. Seems token was working but i need to switch to verification (type?). Im not sure, the documentation is not very good on that.
I think one of the devs need to revist this and make sure it works and is documented correctly.
args.type
is one of "oauth" | "email" | "phone" | "credentials" | "verification"
yet you can see in my logs create email & user:
-> Oct 29, 19:15:42 M auth:store info 'auth:store
type: createVerificationCode'
and link clicked:
-> Oct 29, 19:15:54 M auth:store info 'auth:store
type: verifyCodeAndSignIn'
Those types don't match up. So im at a loss as to how to handle the flow.
maybe somehow detect that its a "clicked email link" and add use (in link the code from this table), and test it against the code and update db and redirect?Ok yeah our docs + examples here are not very clear. I believe the way the
Email
provider in Convex Auth is written only works with OTPs (does not work with magic links), and expects to be called by something like a form submit where you can provide the email + the code in the signIn
call.
For magic links, I believe you want to use Resend
out of @auth/core/providers/resend
potentially overriding the sendVerificationRequest
option to send a custom email. I believe the URL for the magic link will always use the query param code
and use the URL specified in the redirectTo
param of the signIn
call that creates the code. Convex Auth will automatically inter
Stay tuned for some better docs + examples here, but happy to keep talking here to try and unblock you and get this workingYeah, i really need to figure it out as it has me blocked. i Have been converting this from a working clerk to convex. I am not planning on using OAuth at this time, i just need Email/password, Magic Link (email, cick to verify then set password and phone verification would be nice. I already have Resend configured and running. I also know that Email+Password does work, but was not verifying email.
So i guess I need to Jerry Rig something for now so i can push this for QA and then deploy so I can turn off clerk and move on to the other features/changes.
Should i just create my own separate verification code/components for now? Do you have any idea why the
afterUserCreatedOrUpdated(ctx, args)
is not being called?chiming in here, i think
afterUserCreatedOrUpdated
is called by the default user creation
it looks like you're providing your own createOrUpdateUser
which means you'll need to call afterUserCreatedOrUpdated
in your custom codeit also looks like you can override the
email
requirement for magic links:
https://labs.convex.dev/auth/api_reference/providers/Emailproviders/Email - Convex Auth
Authentication library for your Convex backend
How did you end up solving this issue? If you don't mind, please share. Thanks!
It's still unsolved. Responded to issue on github but no responses. So, it's still not working, I left it and moved on with other parts of the app.
@NlaakALD - so, I tried rather hard to refactor a running application to use convex-auth to no avail. Was on this process for almost a week. Decided to run the template-nextjs-convexauth-shadcn repo and that worked. I am now porting my app into that app...it's a bit of a drag but, thus far, it's the only way I am able to move forward.
I'll check it out. Thanks for the 411