feat: implement user authentication, profile management, and email verification with i18n support
This commit is contained in:
parent
06db182c46
commit
b2365a4c6a
6 changed files with 271 additions and 17 deletions
|
|
@ -8,7 +8,7 @@ useHead({
|
|||
title: 'ตั้งค่าบัญชี - e-Learning'
|
||||
})
|
||||
|
||||
const { currentUser, updateUserProfile, changePassword, uploadAvatar, sendVerifyEmail } = useAuth()
|
||||
const { currentUser, updateUserProfile, changePassword, uploadAvatar, sendVerifyEmail, fetchUserProfile } = useAuth()
|
||||
const { t } = useI18n()
|
||||
|
||||
|
||||
|
|
@ -40,9 +40,25 @@ const userData = ref({
|
|||
phone: currentUser.value?.phone || '',
|
||||
createdAt: formatDate(currentUser.value?.createdAt),
|
||||
photoURL: currentUser.value?.photoURL || '',
|
||||
prefix: currentUser.value?.prefix?.th || ''
|
||||
prefix: currentUser.value?.prefix?.th || '',
|
||||
emailVerifiedAt: currentUser.value?.emailVerifiedAt
|
||||
})
|
||||
|
||||
// ...
|
||||
|
||||
// Watch for changes in global user state (e.g. after avatar upload)
|
||||
watch(() => currentUser.value, (newUser) => {
|
||||
if (newUser) {
|
||||
userData.value.photoURL = newUser.photoURL || ''
|
||||
userData.value.firstName = newUser.firstName
|
||||
userData.value.lastName = newUser.lastName
|
||||
userData.value.prefix = newUser.prefix?.th || ''
|
||||
userData.value.email = newUser.email
|
||||
userData.value.phone = newUser.phone || ''
|
||||
userData.value.emailVerifiedAt = newUser.emailVerifiedAt
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
const passwordForm = reactive({
|
||||
currentPassword: '',
|
||||
newPassword: '',
|
||||
|
|
@ -184,7 +200,8 @@ watch(() => currentUser.value, (newUser) => {
|
|||
}
|
||||
}, { deep: true })
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await fetchUserProfile(true)
|
||||
isHydrated.value = true
|
||||
})
|
||||
</script>
|
||||
|
|
@ -269,8 +286,10 @@ onMounted(() => {
|
|||
<ProfileEditForm
|
||||
v-model="userData"
|
||||
:loading="isProfileSaving"
|
||||
:verifying="isSendingVerify"
|
||||
@submit="handleUpdateProfile"
|
||||
@upload="handleFileUpload"
|
||||
@verify="handleSendVerifyEmail"
|
||||
/>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue