2022-09-26 16:23:45 +02:00
|
|
|
<template>
|
2022-09-26 16:59:49 +02:00
|
|
|
<div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md">
|
|
|
|
<form @submit.prevent="saveEmail" class="flex flex-col">
|
2022-09-26 17:01:50 +02:00
|
|
|
<p class="mb-5 text-lg text-red-500 font-bold">Let op! Je verandert alleen het Email van de app dus <u>NIET</u> van de vereniging!</p>
|
2022-09-26 16:59:49 +02:00
|
|
|
<label class="font-bold">Password</label>
|
|
|
|
<input v-model="password" required="true" class="input " :type="showPassword ? 'text' : 'password'">
|
|
|
|
|
|
|
|
<div class="mb-5 mt-1 flex items-center text-default">
|
|
|
|
<input v-model="showPassword" type="checkbox" class="mr-1 checkbox ">
|
|
|
|
<span>Show Password</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<label class="font-bold">New Email</label>
|
|
|
|
<input v-model="email" required="true" placeholder="user@example.com" class="input mb-5" type="email">
|
|
|
|
|
|
|
|
<div class="w-full flex flex-wrap justify-between">
|
|
|
|
<input :disabled="disableButtons" type="submit" value="Change Email" class="btn w-full sm:w-40 mb-1">
|
|
|
|
<button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Cancel</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
2022-09-26 16:23:45 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2022-09-26 16:59:49 +02:00
|
|
|
import { reauthenticateWithCredential, EmailAuthProvider, updateEmail } from 'firebase/auth'
|
|
|
|
import { updateDoc, doc } from 'firebase/firestore'
|
|
|
|
import { useToast } from 'vue-toastification'
|
|
|
|
|
2022-09-26 16:23:45 +02:00
|
|
|
definePageMeta({
|
2022-09-26 16:59:49 +02:00
|
|
|
title: 'Change Password',
|
2022-09-26 16:23:45 +02:00
|
|
|
key: 'back'
|
|
|
|
})
|
2022-09-26 16:59:49 +02:00
|
|
|
|
|
|
|
const { user, auth, db } = inject('firebase')
|
|
|
|
|
|
|
|
const toast = useToast()
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const password = ref('')
|
|
|
|
const email = ref('')
|
|
|
|
const disableButtons = ref(false)
|
|
|
|
const showPassword = ref(false)
|
|
|
|
|
|
|
|
const saveEmail = () => {
|
|
|
|
disableButtons.value = true
|
2022-09-26 17:01:50 +02:00
|
|
|
|
2022-09-26 16:59:49 +02:00
|
|
|
const credential = EmailAuthProvider.credential(
|
|
|
|
user.value.email,
|
|
|
|
password.value
|
|
|
|
)
|
|
|
|
|
|
|
|
reauthenticateWithCredential(auth.value.currentUser, credential).then(() => {
|
|
|
|
updateEmail(auth.value.currentUser, email.value).then(async () => {
|
|
|
|
await updateDoc(doc(db, "users", user.value.uid), {
|
|
|
|
email: email.value
|
|
|
|
})
|
|
|
|
|
|
|
|
toast.success('Email is veranderd')
|
|
|
|
|
|
|
|
navigateTo('/settings')
|
|
|
|
disableButtons.value = false
|
|
|
|
}).catch((error) => {
|
|
|
|
toast.error('Error tijdens het email veranderen')
|
|
|
|
console.log(error)
|
|
|
|
disableButtons.value = false
|
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
disableButtons.value = false
|
|
|
|
|
|
|
|
if (error.code === 'auth/wrong-password') return toast.error('Wachtwoord is onjuist')
|
|
|
|
|
|
|
|
toast.error('Error tijdens het email veranderen')
|
|
|
|
|
|
|
|
console.log(error)
|
|
|
|
});
|
|
|
|
}
|
2022-09-26 16:23:45 +02:00
|
|
|
</script>
|