#Import Users

4 messages · Page 1 of 1 (latest)

sudden owl
#

I am creating a dashboard where admins can upload a csv with email and temporary password and people will get emails with verification code and they can signin and reset password, what's the best approach?
i mean do I have to call the signIn method individually? using convex auth

neon stormBOT
#

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:

  1. Parse the CSV file to extract the email and temporary password for each user.
  2. For each user, call the signIn function from Convex with the password provider and the signUp flow. 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).

If you need more advanced user management features, you might want to consider using a dedicated user management service like Clerk, as suggested in the Discord support thread (https://discord.com/channels/1019350475847499849/1279376450688122880).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: