rootlexR
Convex Community12mo ago
1 reply
rootlex

User document is deleted when I try to reset password

So I tried implementing reset password, I used the instructions in the doc. So I started by setting up resend and setting up my auth.ts.

import { convexAuth } from "@convex-dev/auth/server";
import { Password } from "@convex-dev/auth/providers/Password";
import { internal } from "./_generated/api";
import { ResendOTPPasswordReset } from "./otp/ResendResetPassword";

export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
    providers: [
        Password({
            reset: ResendOTPPasswordReset,
        }),
    ],
    callbacks: {
        async afterUserCreatedOrUpdated(ctx, args) {
            const userId = args.userId;
            const user = await ctx.db.get(userId);

            if (!user) return console.log("No user found");

            await ctx.runMutation(internal.services.auth.runUserAccountUpdate, {
                email: user.email,
                userId,
            });
        },
    },
});


But when I try to use the reset command in my code by sending a verification code, it deletes the user document.

  signIn("password", {
                        email: values.email,
                        flow: "reset",
})


And when I try to request for OTP again, I get this error:

"Could not update user document with ID
jx71ve8bbf3c27qm0whh3ye0657a9ma2
, either the user has been deleted but their account has not, or the profile data doesn't match the
users
table schema: Update on nonexistent document ID jx71ve8bbf3c27qm0whh3ye0657a9ma2"

Please I have been on this for a couple of days. The whole convex auth is really difficult to manage
Was this page helpful?