#Import Users
4 messages · Page 1 of 1 (latest)
Hi @sudden owl. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the information provided in the knowledge sources, Convex does not have a built-in feature for bulk user import via CSV. However, you can build such a feature yourself by leveraging the Convex authentication system.
Here's a general approach you could take:
- Parse the CSV file to extract the email and temporary password for each user.
- For each user, call the
signInfunction from Convex with thepasswordprovider and thesignUpflow. This will create a new user account with the provided email and temporary password.
Here's an example of how you might call the signIn function for a single user:
const { signIn } = useAuthActions();
const formData = new FormData();
formData.append('email', 'user@example.com');
formData.append('password', 'temporaryPassword');
formData.append('flow', 'signUp');
signIn('password', formData);
After the user accounts are created, the users can sign in using their email and temporary password. They can then reset their password using the password reset flow provided by Convex. The password reset flow sends a code to the user's email, which they can use to set a new password.
Here's an example of how you might implement the password reset form:
const { signIn } = useAuthActions();
const [step, setStep] = useState<"forgot" | { email: string }>("forgot");
return step === "forgot" ? (
<form
onSubmit={(event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
void signIn("password", formData).then(() =>
setStep({ email: formData.get("email") as string }),
);
}}
>
<input name="email" placeholder="Email" type="text" />
<input name="flow" type="hidden" value="reset" />
<button type="submit">Send code</button>
</form>
) : (
// ...
);
Please note that this is a simplified example and you would need to handle errors and edge cases in a real-world application. Also, this approach would require the signIn function to be called individually for each user, which might not be efficient for a large number of users.
For more information, you can refer to the Convex documentation on password-based authentication (https://labs.convex.dev/auth/config/passwords) and password reset flow (https://labs.convex.dev/auth/config/passwords#email-reset-setup).