export const useEnrollMfa = <Channel extends Setup2faChannel>({
channel,
}: {
channel: Channel;
}) => {
return useMutation({
mutationKey: ["mfaEnroll", channel],
mutationFn: async ({ phoneNumber }: { phoneNumber: string }) => {
const factors = await supabase.auth.mfa.listFactors();
if (factors.error) {
captureException("Failed to list MFA factors.", {
level: "error",
extra: { factorsError: factors.error },
});
throw factors.error;
}
const { data } = await supabase.auth.mfa.enroll({
factorType: "phone",
phone: phoneNumber, // in E.164 format
friendlyName: "smsA",
});
return data;
},
});
};
export const useEnrollMfa = <Channel extends Setup2faChannel>({
channel,
}: {
channel: Channel;
}) => {
return useMutation({
mutationKey: ["mfaEnroll", channel],
mutationFn: async ({ phoneNumber }: { phoneNumber: string }) => {
const factors = await supabase.auth.mfa.listFactors();
if (factors.error) {
captureException("Failed to list MFA factors.", {
level: "error",
extra: { factorsError: factors.error },
});
throw factors.error;
}
const { data } = await supabase.auth.mfa.enroll({
factorType: "phone",
phone: phoneNumber, // in E.164 format
friendlyName: "smsA",
});
return data;
},
});
};