feat: change mail and change password
This commit is contained in:
@@ -53,28 +53,45 @@ const ChangeEmailAddress = () => {
|
||||
const uid = user?.uid
|
||||
if (!user || !uid) return
|
||||
|
||||
// Reauthenticate user with current password before sensitive update
|
||||
try {
|
||||
const credential = firebase.auth.EmailAuthProvider.credential(user.email, currentPassword)
|
||||
await user.reauthenticateWithCredential(credential)
|
||||
} catch (reauthErr) {
|
||||
throw {
|
||||
code: 'auth/wrong-password',
|
||||
message: 'Mot de passe incorrect.',
|
||||
}
|
||||
setTooltip({ type: 'error', text: 'Mot de passe actuel incorrect.' })
|
||||
return
|
||||
}
|
||||
|
||||
await user.updateEmail(val)
|
||||
await usersRef.doc(uid).set({ email: val }, { merge: true })
|
||||
setTooltip({ type: 'success', text: 'Email mis à jour' })
|
||||
goBack()
|
||||
// Use verifyBeforeUpdateEmail instead of updateEmail for newer Firebase projects
|
||||
// This sends a verification email to the new address and only changes it once verified.
|
||||
// However, for some projects, we might still need to update Firestore record if allowed.
|
||||
try {
|
||||
if (typeof user.verifyBeforeUpdateEmail === 'function') {
|
||||
await user.verifyBeforeUpdateEmail(val)
|
||||
setTooltip({
|
||||
type: 'success',
|
||||
text: 'Un email de vérification a été envoyé à votre nouvelle adresse.',
|
||||
})
|
||||
} else {
|
||||
await user.updateEmail(val)
|
||||
await usersRef.doc(uid).set({ email: val }, { merge: true })
|
||||
setTooltip({ type: 'success', text: 'Adresse email mise à jour' })
|
||||
}
|
||||
goBack()
|
||||
} catch (updateErr) {
|
||||
console.log('UpdateEmail error detail', updateErr)
|
||||
let msg = 'Mise à jour impossible'
|
||||
if (updateErr.code === 'auth/operation-not-allowed') {
|
||||
msg = "La modification d'email directe n'est pas autorisée. Contactez le support."
|
||||
} else if (updateErr.message?.includes('verify')) {
|
||||
msg = "Veuillez vérifier votre nouvel email avant d'effectuer le changement."
|
||||
} else {
|
||||
msg = updateErr.message || msg
|
||||
}
|
||||
setTooltip({ type: 'error', text: msg })
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('ChangeEmailAddress error', e?.message)
|
||||
const msg =
|
||||
e?.code === 'auth/requires-recent-login'
|
||||
? "Veuillez vous reconnecter pour changer l'adresse email"
|
||||
: e?.message || 'Mise à jour impossible'
|
||||
setTooltip({ type: 'error', text: msg })
|
||||
console.log('ChangeEmailAddress error', e)
|
||||
setTooltip({ type: 'error', text: e?.message || 'Une erreur est survenue' })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
@@ -82,7 +99,7 @@ const ChangeEmailAddress = () => {
|
||||
return (
|
||||
<Page
|
||||
headerType="NAVIGATE"
|
||||
title="Paramètres"
|
||||
title="Modifier mon email"
|
||||
backgroundImg={background.profileBG}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: gutters * 4,
|
||||
|
||||
Reference in New Issue
Block a user