passphrase prompt
This commit is contained in:
@@ -3,19 +3,19 @@ import { useTitle } from '@vueuse/core'
|
||||
import { doc, getDoc } from 'firebase/firestore'
|
||||
import { viewModes, activeViewMode } from '@/composables/useViewMode'
|
||||
import { initialized, user, db } from '@/composables/useFirebase'
|
||||
import { decryptNotes, getEncryptionKey } from '@/composables/useEncryption'
|
||||
import { decryptNotes, encryptionKey } from '@/composables/useEncryption'
|
||||
import { defaultNotes } from '@/utils/defaultNotes'
|
||||
import { mdToHtml } from '@/utils/markdown'
|
||||
import { getAllMatches } from '@/utils/helpers'
|
||||
|
||||
const notesSources = computed(() => ({
|
||||
export const notesSources = computed(() => ({
|
||||
local: true,
|
||||
firebase: initialized.value && user.value
|
||||
}))
|
||||
|
||||
type notesSourceValues = keyof typeof notesSources.value | null
|
||||
|
||||
const activeNotesSource = ref<notesSourceValues>(null)
|
||||
export const activeNotesSource = ref<notesSourceValues>(null)
|
||||
|
||||
watchEffect(() => {
|
||||
const getSource = (): notesSourceValues => {
|
||||
@@ -29,14 +29,14 @@ const baseNotes = ref<{ [noteId: string]: BaseNote }>({})
|
||||
watch(
|
||||
baseNotes,
|
||||
() => {
|
||||
console.log(`Sync base notes with ${activeNotesSource.value}`, baseNotes.value)
|
||||
if (!activeNotesSource.value) return
|
||||
if (!activeNotesSource.value || Object.keys(baseNotes.value).length === 0) return
|
||||
if (activeNotesSource.value === 'local') {
|
||||
console.log('sync with local')
|
||||
localStorage.setItem('notes', JSON.stringify(baseNotes.value))
|
||||
} else if (activeNotesSource.value === 'firebase') {
|
||||
console.log('sync with firebase')
|
||||
}
|
||||
console.log(`Sync base notes with ${activeNotesSource.value}`, baseNotes.value)
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
@@ -209,7 +209,7 @@ const parseBaseNotes = (notes: BaseNotes): BaseNotes => {
|
||||
}
|
||||
|
||||
watch(
|
||||
activeNotesSource,
|
||||
[activeNotesSource, encryptionKey],
|
||||
async () => {
|
||||
if (!activeNotesSource.value) return
|
||||
baseNotes.value = {}
|
||||
@@ -221,11 +221,11 @@ watch(
|
||||
console.log(error)
|
||||
}
|
||||
} else if (activeNotesSource.value === 'firebase' && db.value) {
|
||||
if (encryptionKey.value === undefined) return
|
||||
const firebaseNotes = (
|
||||
await getDoc(doc(db.value, 'pages', user.value?.uid || ''))
|
||||
).data() as { [noteId: string]: any }
|
||||
const encryptionKey = await getEncryptionKey()
|
||||
notes = encryptionKey ? decryptNotes(firebaseNotes, encryptionKey) : firebaseNotes
|
||||
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