Magic link not creating account

Some users signed in using magic link in their first time and when they try to sign in with magic link again, the link's not working. I've noticed that signing in with magic link doesn't create an account in accounts table. Could that be the issue? I've tried only signing in with magic link and it worked even though account is not created. Is magic link supposed to be used only for signing in, not signing up?
8 Replies
nainglinnkhant
nainglinnkhantOP4mo ago
@bekacru can you please check this?
Soheel
Soheel4mo ago
https://www.better-auth.com/docs/plugins/magic-link#usage Here it says unless you disabled signup with disableSignUp in the magic-link config the user should theoretically be signed up alongside the session creation if the user did not have an account prior
Magic link | Better Auth
Magic link plugin
Soheel
Soheel4mo ago
However, it is intentional that Magic-Links only work once, magic-links revolve around being one-time use and only valid for a specific timeframe, otherwise you would literally create a backdoor to the users account into your application each time they issue a magic-link
Soheel
Soheel4mo ago
Expire after 5 minutes per default, can only be used once to sign-in (as it should be) Unless I understood you wrong and that issuing a new magic link resulted in them being unable to log in with that, that then would be a legitimate error within the current magic-link implementation
Soheel
Soheel4mo ago
Also regarding not an Account being created for the user, as I read from the Schema an Account is only necessary in case of password authentification or if the user uses OTP where a specific secret has to be stored for each user. As magic-links do not require this no Account entry has to be issued for the user, just check that a "User" Entry is created. https://www.better-auth.com/docs/concepts/database
Database | Better Auth
Learn how to use a database with Better Auth.
Louis
Louis4mo ago
Hey team, based on my research, everything discussed so far makes sense and aligns with my understanding. However, I haven't been able to find more information on whether it's possible to do account linking if a user first signs up with magic link, then tries to sign in with an OAuth provider. I have accountLinking enabled and have added items to trustedProviders. I'm getting an error
ERROR [Better Auth]: error: duplicate key value violates unique constraint "users_email_key"
ERROR [Better Auth]: error: duplicate key value violates unique constraint "users_email_key"
which suggests OAuth flow is trying to create a new user despite one already existing when it was created with magic link. Am I missing something? TIA! Apologies if unrelated, happy to open as a separate post
nainglinnkhant
nainglinnkhantOP4mo ago
Yes, I've seen that magic links can be used to sign up too but just confirming if it's the really intended way since some users who only use magic link to sign in are facing the issue. What's weird is that it's only happening to some accounts and I can't reproduce it either. Thanks for your answer anyway. I've looked through the logs the other day and /magic-link/verify is 404 sometimes. That could be the issue but not sure yet.

Did you find this page helpful?