[GH-ISSUE #473] Signup with magic link doesn't create an account. #16914

Closed
opened 2026-04-15 14:52:57 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @opswiz on GitHub (Nov 9, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/473

Describe the bug

Signup with magic link successfully creates a user, but doesn't create an account.

To Reproduce
Steps to reproduce the behavior:

  1. Send a magic link
  2. Click on magic link or verify it manually
  3. no account created

Expected behavior

Following https://github.com/better-auth/better-auth/issues/173 Signup with magic links creates an user after verification but not account, it should create account.

Additional context

It is fairly common to signup with just links or one time codes. for example linear.app and many more and set password later in the account if needed or just continue use it without any passwords forever. Thus enabling passwordless flow.

As a workaround what currently works is via manual verification

const resp = await auth.api.magicLinkVerify({
      query: { token: payload.code },
      headers: await headers(),
      asResponse: true,
});

// set cookies
// get user account
// check if has an account 
// if not link it manually
auth.api.setPassword()

This fails in the context of magic links thought, where it cannot be intercepted and accounts cannot be created.

Originally created by @opswiz on GitHub (Nov 9, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/473 **Describe the bug** Signup with magic link successfully creates a user, but doesn't create an account. **To Reproduce** Steps to reproduce the behavior: 1. Send a magic link 2. Click on magic link or verify it manually 3. no account created **Expected behavior** Following https://github.com/better-auth/better-auth/issues/173 Signup with magic links creates an user after verification but not account, it should create account. **Additional context** It is fairly common to signup with just links or one time codes. for example [linear.app](https://linear.app/) and many more and set password later in the account if needed or just continue use it without any passwords forever. Thus enabling passwordless flow. As a workaround what currently works is via manual verification ```js const resp = await auth.api.magicLinkVerify({ query: { token: payload.code }, headers: await headers(), asResponse: true, }); // set cookies // get user account // check if has an account // if not link it manually auth.api.setPassword() ``` This fails in the context of magic links thought, where it cannot be intercepted and accounts cannot be created.
GiteaMirror added the locked label 2026-04-15 14:52:57 -05:00
Author
Owner

@Bekacru commented on GitHub (Nov 9, 2024):

Account doesn't need to be created for magic link and email otp, since it'd serve no purpose. If you need to link their account to a credential, you either need to sign the user with email or use api.setPassword as you're doing now.

<!-- gh-comment-id:2466224272 --> @Bekacru commented on GitHub (Nov 9, 2024): Account doesn't need to be created for magic link and email otp, since it'd serve no purpose. If you need to link their account to a credential, you either need to sign the user with email or use `api.setPassword` as you're doing now.
Author
Owner

@opswiz commented on GitHub (Nov 9, 2024):

Yeah, this is working fine with do manual verification where I redirect user to page and when they enter the token I check and do the above, the problem is that when magic links are clicked directly, unable to intercept and create account. Not sure if I missed anything.

you either need to sign the user with email

you mean, username password flow?

<!-- gh-comment-id:2466227838 --> @opswiz commented on GitHub (Nov 9, 2024): Yeah, this is working fine with do manual verification where I redirect user to page and when they enter the token I check and do the above, the problem is that when magic links are clicked directly, unable to intercept and create account. Not sure if I missed anything. > you either need to sign the user with email you mean, username password flow?
Author
Owner

@Bekacru commented on GitHub (Nov 9, 2024):

wait why would you want to create an account after the user clicks the magic link? Maybe I'm misunderstanding, but how would you have the password in the first place to create them a credential account when they click the magic link? If you need to set a password for the user after they sign up, you can use auth.api.setPassword

<!-- gh-comment-id:2466240771 --> @Bekacru commented on GitHub (Nov 9, 2024): wait why would you want to create an account after the user clicks the magic link? Maybe I'm misunderstanding, but how would you have the password in the first place to create them a credential account when they click the magic link? If you need to set a password for the user after they sign up, you can use `auth.api.setPassword`
Author
Owner

@opswiz commented on GitHub (Nov 9, 2024):

May be yeah the misunderstanding. Let me be clear on what I am trying to do. May be my expectation on implementation with BA could be wrong too.

What I am trying to do is signup for an account with email without password. So one can enter the email, and get a token or click on a link to finish signup.

wait why would you want to create an account after the user clicks the magic link?

the reason is that the entities I create afterwards signing up are linked to an account and not an user. So that in future, when an invite flow is added, the resourced created are tied to an account, and I can make someone else the owner and the resources are not affected.

Also I just noticed organization, its at the bottom end of the sidebar and half hidden and I am just seeing it, the sidebar does not scroll after it expanded in my 13inch mac. May be I am looking for that? 🤔

Screenshot 2024-11-09 at 8 19 37 PM
<!-- gh-comment-id:2466248291 --> @opswiz commented on GitHub (Nov 9, 2024): May be yeah the misunderstanding. Let me be clear on what I am trying to do. May be my expectation on implementation with BA could be wrong too. What I am trying to do is signup for an account with email without password. So one can enter the email, and get a token or click on a link to finish signup. > wait why would you want to create an account after the user clicks the magic link? the reason is that the entities I create afterwards signing up are linked to an account and not an user. So that in future, when an invite flow is added, the resourced created are tied to an account, and I can make someone else the owner and the resources are not affected. Also I just noticed organization, its at the bottom end of the sidebar and half hidden and I am just seeing it, the sidebar does not scroll after it expanded in my 13inch mac. May be I am looking for that? 🤔 <img width="1459" alt="Screenshot 2024-11-09 at 8 19 37 PM" src="https://github.com/user-attachments/assets/aab0f1e4-1ee3-4b05-a6fb-f5d105417a53">
Author
Owner

@Bekacru commented on GitHub (Nov 9, 2024):

the resourced created are tied to an account

a user can have multiple accounts. An account is just a list of providers the user has linked to get authenticated. OAuth providers or email and password (credential).

<!-- gh-comment-id:2466275331 --> @Bekacru commented on GitHub (Nov 9, 2024): > the resourced created are tied to an account a user can have multiple accounts. An account is just a list of providers the user has linked to get authenticated. OAuth providers or email and password (credential).
Author
Owner

@opswiz commented on GitHub (Nov 9, 2024):

My bad, i got it confused with literal account and didn't notice organization.

Closing this issue. Since the requested context is different and answered.

<!-- gh-comment-id:2466279616 --> @opswiz commented on GitHub (Nov 9, 2024): My bad, i got it confused with literal account and didn't notice organization. Closing this issue. Since the requested context is different and answered.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16914