feat: factory reset, backup restore, auto-identity creation
- system.factory-reset RPC: wipes user data, preserves images/node_key - Factory Reset button in Settings with confirmation modal - backup.restore-identity RPC: decrypts and restores DID key - Restore from Backup panel in OnboardingIntro first screen - Auto-create default identity with Nostr key on boot if none exist Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,20 +23,103 @@
|
||||
>
|
||||
Unlock your sovereignty →
|
||||
</button>
|
||||
|
||||
<a
|
||||
class="text-white/50 hover:text-white/80 underline text-sm cursor-pointer mt-4 block text-center onb-cta"
|
||||
@click="showRestore = true"
|
||||
>
|
||||
Restore from backup
|
||||
</a>
|
||||
|
||||
<!-- Restore Panel -->
|
||||
<div v-if="showRestore" class="mt-6 glass-card px-6 py-6 text-left">
|
||||
<h3 class="text-sm font-semibold text-white/80 mb-3 uppercase tracking-wide">Restore Identity from Backup</h3>
|
||||
<input
|
||||
type="file"
|
||||
accept=".json"
|
||||
class="block w-full text-sm text-white/60 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:bg-white/10 file:text-white/80 hover:file:bg-white/20 mb-3"
|
||||
@change="onFileSelect"
|
||||
/>
|
||||
<input
|
||||
v-model="passphrase"
|
||||
type="password"
|
||||
placeholder="Backup passphrase"
|
||||
class="w-full px-4 py-2 bg-white/10 border border-white/20 rounded-lg text-white text-sm focus:outline-none focus:border-white/40 mb-3"
|
||||
/>
|
||||
<p v-if="restoreError" class="text-red-400 text-xs mb-2">{{ restoreError }}</p>
|
||||
<p v-if="restoreSuccess" class="text-green-400 text-xs mb-2">Identity restored successfully!</p>
|
||||
<div class="flex gap-3">
|
||||
<button class="glass-button text-sm px-4 py-2" @click="showRestore = false">Cancel</button>
|
||||
<button
|
||||
class="glass-button text-sm px-4 py-2"
|
||||
:disabled="!restoreFile || !passphrase || restoreLoading"
|
||||
@click="performRestore"
|
||||
>
|
||||
{{ restoreLoading ? 'Restoring...' : 'Restore' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import AnimatedLogo from '@/components/AnimatedLogo.vue'
|
||||
import { rpcClient } from '@/api/rpc-client'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
function goToOptions() {
|
||||
router.push('/onboarding/path').catch(() => {})
|
||||
}
|
||||
|
||||
// Restore from backup
|
||||
const showRestore = ref(false)
|
||||
const restoreFile = ref<Record<string, unknown> | null>(null)
|
||||
const passphrase = ref('')
|
||||
const restoreLoading = ref(false)
|
||||
const restoreError = ref('')
|
||||
const restoreSuccess = ref(false)
|
||||
|
||||
function onFileSelect(e: Event) {
|
||||
const target = e.target as HTMLInputElement
|
||||
const file = target.files?.[0]
|
||||
if (!file) return
|
||||
const reader = new FileReader()
|
||||
reader.onload = () => {
|
||||
try {
|
||||
restoreFile.value = JSON.parse(reader.result as string)
|
||||
restoreError.value = ''
|
||||
} catch {
|
||||
restoreError.value = 'Invalid backup file format'
|
||||
restoreFile.value = null
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
|
||||
async function performRestore() {
|
||||
if (!restoreFile.value || !passphrase.value) return
|
||||
restoreLoading.value = true
|
||||
restoreError.value = ''
|
||||
try {
|
||||
await rpcClient.call({
|
||||
method: 'backup.restore-identity',
|
||||
params: { backup: restoreFile.value, passphrase: passphrase.value },
|
||||
})
|
||||
restoreSuccess.value = true
|
||||
setTimeout(() => {
|
||||
router.push('/onboarding/did')
|
||||
}, 1500)
|
||||
} catch (err) {
|
||||
restoreError.value = err instanceof Error ? err.message : 'Restore failed'
|
||||
} finally {
|
||||
restoreLoading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -818,6 +818,42 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Factory Reset Section -->
|
||||
<div class="path-option-card px-6 py-6 mt-6 border-red-500/30">
|
||||
<h2 class="text-xl font-semibold text-red-400/90 mb-3">Factory Reset</h2>
|
||||
<p class="text-sm text-white/60 mb-4">
|
||||
Wipe all user data, identities, and credentials. Container images are preserved. The node will restart and show the onboarding screen.
|
||||
</p>
|
||||
<button
|
||||
class="glass-button text-red-400 border-red-500/30 hover:border-red-500/50"
|
||||
@click="showFactoryResetConfirm = true"
|
||||
>
|
||||
Factory Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Factory Reset Confirmation Modal -->
|
||||
<Teleport to="body">
|
||||
<div v-if="showFactoryResetConfirm" class="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm">
|
||||
<div class="glass-card px-8 py-8 max-w-md mx-4">
|
||||
<h3 class="text-lg font-semibold text-white/90 mb-3">Are you sure?</h3>
|
||||
<p class="text-sm text-white/60 mb-6">
|
||||
This will delete all identities, credentials, and settings. This cannot be undone.
|
||||
</p>
|
||||
<div class="flex gap-3 justify-end">
|
||||
<button class="glass-button" @click="showFactoryResetConfirm = false">Cancel</button>
|
||||
<button
|
||||
class="glass-button text-red-400 border-red-500/30"
|
||||
:disabled="factoryResetLoading"
|
||||
@click="performFactoryReset"
|
||||
>
|
||||
{{ factoryResetLoading ? 'Resetting...' : 'Yes, Reset' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -837,6 +873,24 @@ import type { UIMode } from '@/types/api'
|
||||
const router = useRouter()
|
||||
const { t, locale } = useI18n()
|
||||
const store = useAppStore()
|
||||
|
||||
// Factory Reset
|
||||
const showFactoryResetConfirm = ref(false)
|
||||
const factoryResetLoading = ref(false)
|
||||
async function performFactoryReset() {
|
||||
factoryResetLoading.value = true
|
||||
try {
|
||||
await rpcClient.call({ method: 'system.factory-reset', params: { confirm: true } })
|
||||
localStorage.clear()
|
||||
showFactoryResetConfirm.value = false
|
||||
router.push('/onboarding/intro')
|
||||
} catch (err) {
|
||||
// Service likely restarted — redirect anyway
|
||||
localStorage.clear()
|
||||
showFactoryResetConfirm.value = false
|
||||
router.push('/onboarding/intro')
|
||||
}
|
||||
}
|
||||
const supportedLocales = SUPPORTED_LOCALES
|
||||
const currentLocale = computed(() => locale.value)
|
||||
async function changeLocale(code: string) {
|
||||
|
||||
Reference in New Issue
Block a user