Using Tanstack Start with Convex Auth and Resend as provider with Magic Link.
The issue is that I already had existing users signing in with Clerk.
How can I avoid duplication of users by same email without having to use createOrUpdateUser callback?
Or should I use the callback while every user signs in at least once with Convex Auth and then remove the callback?
Setup:
auth.ts
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
ResendProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
async sendVerificationRequest({ identifier: to, provider, url }) {
if (provider.apiKey === undefined) {
console.error("Set up `AUTH_RESEND_KEY` to send auth emails");
return;
}
try {
const resend = new Resend(process.env.AUTH_RESEND_KEY!);
const res = await resend.emails.send({
from: "Company <[email protected]>",
to,
subject: `Iniciar sesión en Fentexhaus.mx`,
react: FxSignInEmail({ url }),
text: `Iniciar sesión en fentexhaus.mx: ${url}`,
});
if (res.error)
throw new Error("Resend error: " + JSON.stringify(res.error));
} catch (error) {
console.error("Failed to send verification email:", error);
throw error;
}
},
}),
],
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30, // 30 days
inactiveDurationMs: 1000 * 60 * 60 * 24 * 30, // 30 days
},
});
schema.ts
users: defineTable({
bz_distributorId: v.optional(v.string()),
email: v.optional(v.string()),
emailVerificationTime: v.optional(v.number()),
image: v.optional(v.string()),
isAnonymous: v.optional(v.boolean()),
name: v.optional(v.string()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.number()),
}).index("email", ["email"]),