delete account
This commit is contained in:
@@ -33,7 +33,6 @@ provide('firebaseAuthUI', firebaseAuthUI)
|
||||
watch(
|
||||
[activeNotesSource, encryptionKey],
|
||||
() => {
|
||||
console.log(activeNotesSource.value)
|
||||
if (activeNotesSource.value === 'firebase') {
|
||||
getClientKey()
|
||||
getEncryptionKey()
|
||||
|
||||
@@ -41,17 +41,17 @@ const authModalInitialStateOpen = ref<boolean>(authUI.isPendingRedirect())
|
||||
<UIButton
|
||||
size="sm"
|
||||
variant="outline"
|
||||
class="search-active-hide py-1 text-white topbar-button"
|
||||
class="search-active-hide topbar-button text-white"
|
||||
@click="addNote('Untitled new note', '', true)"
|
||||
>
|
||||
<i class="fas fa-plus-circle text-[1.1rem]" />
|
||||
<i class="fa-fw fa-solid fa-plus-circle scale-[115%]" />
|
||||
</UIButton>
|
||||
<UIModal v-if="initialized && !user" :open="authModalInitialStateOpen">
|
||||
<template #activator="{ open }">
|
||||
<UIButton
|
||||
size="sm"
|
||||
variant="outline"
|
||||
class="search-active-hide py-1 text-white topbar-button"
|
||||
class="search-active-hide topbar-button py-1 text-white"
|
||||
@click="open"
|
||||
>
|
||||
Sign in
|
||||
|
||||
@@ -9,7 +9,7 @@ import { OnClickOutside } from '@vueuse/components'
|
||||
:dropdown="true"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
class="topbar-button py-1 text-white"
|
||||
class="topbar-button text-white"
|
||||
>
|
||||
<i class="fa-fw fa-solid fa-user-gear" />
|
||||
</UIButton>
|
||||
|
||||
@@ -24,8 +24,8 @@ const exportNotes = async () => {
|
||||
}
|
||||
|
||||
const showDeleteAccountDialog = ref(false)
|
||||
const deleteAccount = () => {
|
||||
console.log('delete account')
|
||||
const deleteAccount = async () => {
|
||||
await user.value?.delete()
|
||||
}
|
||||
|
||||
const showEncryptionDialog = ref(false)
|
||||
@@ -71,7 +71,7 @@ const toggleEncryption = async () => {
|
||||
<div>{{ user?.email }}</div>
|
||||
</div>
|
||||
<div class="w-full flex-row sm:flex">
|
||||
<div class="font-bold sm:w-4/12">Verified</div>
|
||||
<div class="font-bold sm:w-4/12">Account status</div>
|
||||
<div class="col-auto">
|
||||
<UIBadge :color="user?.emailVerified ? 'success' : 'warning'">
|
||||
{{ user?.emailVerified ? 'Verified' : 'Not yet verified' }}
|
||||
|
||||
@@ -40,8 +40,15 @@ const styleClass = computed(() => {
|
||||
})
|
||||
</script>
|
||||
<template>
|
||||
<label class="dui-btn duration-0" :class="styleClass" v-if="props.dropdown" tabindex="0">
|
||||
<label
|
||||
class="dui-btn h-auto px-3 py-2 duration-0"
|
||||
:class="styleClass"
|
||||
v-if="props.dropdown"
|
||||
tabindex="0"
|
||||
>
|
||||
<slot></slot>
|
||||
</label>
|
||||
<button class="dui-btn duration-0" :class="styleClass" v-else><slot></slot></button>
|
||||
<button class="dui-btn h-auto px-3 py-2 duration-0" :class="styleClass" v-else>
|
||||
<slot></slot>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import shortid from 'shortid'
|
||||
import { useTitle } from '@vueuse/core'
|
||||
import { doc, getDoc, updateDoc, deleteField } from 'firebase/firestore'
|
||||
import { doc, getDoc, setDoc } from 'firebase/firestore'
|
||||
import { viewModes, activeViewMode } from '@/composables/useViewMode'
|
||||
import { initialized, user, db } from '@/composables/useFirebase'
|
||||
import { decryptNotes, encryptNotes, encryptionKey } from '@/composables/useEncryption'
|
||||
@@ -45,23 +45,22 @@ const syncNotesLocal = (notes: BaseNotes) => {
|
||||
localStorage.setItem('notes', JSON.stringify(notes))
|
||||
}
|
||||
|
||||
export const syncNotesToFirebase = async (newNotes: BaseNotes, oldNotes?: BaseNotes) => {
|
||||
// export const syncNotesToFirebase = async (newNotes: BaseNotes, oldNotes?: BaseNotes) => {
|
||||
export const syncNotesToFirebase = async (baseNotes: BaseNotes) => {
|
||||
if (!db.value) throw Error("Database undefined, can't sync to Firebase")
|
||||
if (!user.value) throw Error("User undefined, can't sync to Firebase")
|
||||
const notes = encryptionKey.value
|
||||
? encryptNotes(baseNotes.value, encryptionKey.value)
|
||||
: baseNotes.value
|
||||
const notes = encryptionKey.value ? encryptNotes(baseNotes, encryptionKey.value) : baseNotes
|
||||
try {
|
||||
const docRef = doc(db.value, 'pages', user.value.uid)
|
||||
if (oldNotes) {
|
||||
const notesToDelete = Object.keys(oldNotes).filter((x) => !Object.keys(newNotes).includes(x))
|
||||
await Promise.all(
|
||||
notesToDelete.map((noteId: string) => {
|
||||
return updateDoc(docRef, { [noteId]: deleteField() })
|
||||
})
|
||||
)
|
||||
}
|
||||
await updateDoc(docRef, notes)
|
||||
// if (oldNotes) {
|
||||
// const notesToDelete = Object.keys(oldNotes).filter((x) => !Object.keys(newNotes).includes(x))
|
||||
// await Promise.all(
|
||||
// notesToDelete.map((noteId: string) => {
|
||||
// return updateDoc(docRef, { [noteId]: deleteField() })
|
||||
// })
|
||||
// )
|
||||
// }
|
||||
await setDoc(docRef, notes)
|
||||
} catch (error: any) {
|
||||
console.error(error)
|
||||
}
|
||||
@@ -69,12 +68,12 @@ export const syncNotesToFirebase = async (newNotes: BaseNotes, oldNotes?: BaseNo
|
||||
|
||||
watch(
|
||||
baseNotes,
|
||||
async (newBaseNotes, oldBaseNotes) => {
|
||||
async () => {
|
||||
if (!activeNotesSource.value || Object.keys(baseNotes.value).length === 0) return
|
||||
if (activeNotesSource.value === 'local') {
|
||||
syncNotesLocal(baseNotes.value)
|
||||
} else if (activeNotesSource.value === 'firebase') {
|
||||
syncNotesToFirebase(newBaseNotes, oldBaseNotes)
|
||||
syncNotesToFirebase(baseNotes.value)
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
@@ -262,8 +261,9 @@ export const getNotes = async () => {
|
||||
} else if (activeNotesSource.value === 'firebase') {
|
||||
if (encryptionKey.value === undefined || !user.value || !db.value) return
|
||||
const firebaseNotes = (await getDoc(doc(db.value, 'pages', user.value.uid))).data() as BaseNotes
|
||||
notes = encryptionKey.value ? decryptNotes(firebaseNotes, encryptionKey.value) : firebaseNotes
|
||||
console.log(encryptionKey.value)
|
||||
notes = encryptionKey.value
|
||||
? decryptNotes(firebaseNotes, encryptionKey.value)
|
||||
: firebaseNotes || {}
|
||||
console.log('get notes from firebase', notes)
|
||||
}
|
||||
baseNotes.value = parseBaseNotes(notes)
|
||||
|
||||
Reference in New Issue
Block a user