Save failed: user with the same identity already exists -- Making a user manually
I'm not sure how Wasp makes a user how does that work? I need to make a user in the background.
If I write
The user exists in the backend but if they try to login/signup they receive the error
Save failed: user with the same identity already exists
How can I create a user in the background and if they want to sign in they'll have to set a new password (Basically go through the signup again) I think I can figure out this part and it's not WASP specific just the creation of a user I don't fully understand.
2 Replies
Hi @A³Learn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To answer your question about creating a user in the background with Wasp and handling the "Save failed: user with the same identity already exists" error, let's look at how Wasp handles user creation and authentication.
Wasp uses a combination of entities to manage users and authentication. When you create a user manually as you've shown in your code snippet, you're only creating the
User
entity, but not the associated Auth
and AuthIdentity
entities that Wasp uses for authentication.
To properly create a user that can later sign in, you need to use Wasp's built-in functions for user creation. Here's how you can modify your code to create a user correctly:
This approach uses Wasp's createUser
function, which properly sets up all the necessary entities for authentication. The user created this way won't have a password set, so they'll need to go through a signup or password reset flow to set their password before they can log in.
For handling the signup/login for these pre-created users, you'll need to implement a custom signup action. Here's an example of how you might structure this:
This custom signup action checks if the user already exists (which they should if you've pre-created them), and then updates their password. You'll need to define this action in your Wasp file and create a corresponding client-side function to call it.
For more details on custom signup actions and auth entities in Wasp, you can refer to these docs:
1. Custom Signup Action
2. Auth Entities Explained
Remember to handle errors appropriately and provide clear feedback to the user about what's happening during this process.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @A³Learn, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?super this worked.