Create an account on setUserPassword if account does not exist #1557

Closed
opened 2026-03-13 08:48:10 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @jpainam on GitHub (Jul 23, 2025).

Hi, I’m migrating users to better-auth and want them to reset their passwords. However, auth.api.setUserPassword fails if the user doesn’t already have a credential account in the Account table.

New users work fine with signUp since it creates both the user and the account.

Can setUserPassword fallback to creating a credential account if one doesn’t exist?

Originally created by @jpainam on GitHub (Jul 23, 2025). Hi, I’m migrating users to better-auth and want them to reset their passwords. However, `auth.api.setUserPassword` fails if the user doesn’t already have a `credential` account in the `Account` table. New users work fine with `signUp` since it creates both the user and the account. Can setUserPassword fallback to creating a credential account if one doesn’t exist?
GiteaMirror added the enhancement label 2026-03-13 08:48:10 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Aug 11, 2025):

hmm..i guess you should make a fallback to that if you want to make sure to migration work. but i dont think this could be a right fit to have a fallback to on the core api.

@Kinfe123 commented on GitHub (Aug 11, 2025): hmm..i guess you should make a fallback to that if you want to make sure to migration work. but i dont think this could be a right fit to have a fallback to on the core api.
Author
Owner

@neacsugeorge commented on GitHub (Sep 16, 2025):

Hello @Kinfe123 ,

Are there any plans to support this in the future? As an admin user, I am unable to set a user's password if they don't have a credential account. We're currently creating the credential account manually using the ORM and then calling setUserPassword. What would be the expected flow for achieving this with the current better-auth API?

Thank you.

@neacsugeorge commented on GitHub (Sep 16, 2025): Hello @Kinfe123 , Are there any plans to support this in the future? As an admin user, I am unable to set a user's password if they don't have a credential account. We're currently creating the credential account manually using the ORM and then calling setUserPassword. What would be the expected flow for achieving this with the current better-auth API? Thank you.
Author
Owner

@jpainam commented on GitHub (Sep 16, 2025):

Hello @Kinfe123 ,

Are there any plans to support this in the future? As an admin user, I am unable to set a user's password if they don't have a credential account. We're currently creating the credential account manually using the ORM and then calling setUserPassword. What would be the expected flow for achieving this with the current better-auth API?

Thank you.

This is what I ended up doing. Manually inserting the credentials if the user doesn’t have an account yet. And set a password. It also doesn’t allow you to send password reset or password forgot if the user has no credentials.

@jpainam commented on GitHub (Sep 16, 2025): > Hello [@Kinfe123](https://github.com/Kinfe123) , > > Are there any plans to support this in the future? As an admin user, I am unable to set a user's password if they don't have a credential account. We're currently creating the credential account manually using the ORM and then calling setUserPassword. What would be the expected flow for achieving this with the current better-auth API? > > Thank you. This is what I ended up doing. Manually inserting the credentials if the user doesn’t have an account yet. And set a password. It also doesn’t allow you to send password reset or password forgot if the user has no credentials.
Author
Owner

@mjpowersjr commented on GitHub (Oct 29, 2025):

I hit this issue as well. In my case, the user registered via magic link, which did not insert a record into the account table, only the user table.

@mjpowersjr commented on GitHub (Oct 29, 2025): I hit this issue as well. In my case, the user registered via magic link, which did not insert a record into the account table, only the user table.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1557