refactor: Transition to authentication system and remove identity management

- Replace identity management with a new authentication system across the application.
- Update App.vue to integrate LoginDialog and remove PasswordDialog.
- Modify Navbar.vue to handle user authentication state and logout functionality.
- Enhance Home.vue to display user information upon login.
- Implement routing changes in index.ts to enforce authentication requirements for protected routes.
This commit is contained in:
padreug 2025-07-29 23:10:31 +02:00
parent 5ceb12ca3b
commit be4ab13b32
11 changed files with 1065 additions and 96 deletions

View file

@ -1,57 +1,27 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue'
import { onMounted, ref } from 'vue'
import Navbar from '@/components/layout/Navbar.vue'
import Footer from '@/components/layout/Footer.vue'
import PasswordDialog from '@/components/nostr/PasswordDialog.vue'
import LoginDialog from '@/components/auth/LoginDialog.vue'
import { Toaster } from '@/components/ui/sonner'
import 'vue-sonner/style.css'
import { useNostr } from '@/composables/useNostr'
import { identity } from '@/composables/useIdentity'
import { auth } from '@/composables/useAuth'
import { toast } from 'vue-sonner'
import { useNostrStore } from '@/stores/nostr'
const { connect, disconnect } = useNostr()
const nostrStore = useNostrStore()
const showLoginDialog = ref(false)
const showPasswordDialog = ref(false)
async function handlePasswordUnlock(password: string) {
try {
await identity.loadWithPassword(password)
showPasswordDialog.value = false
toast.success('Identity unlocked successfully')
} catch (error) {
toast.error('Failed to unlock identity. Please check your password.')
}
}
function handlePasswordCancel() {
showPasswordDialog.value = false
function handleLoginSuccess() {
showLoginDialog.value = false
toast.success('Welcome back!')
}
onMounted(async () => {
// Check if we have an encrypted identity that needs password
if (identity.hasStoredIdentity() && identity.isStoredIdentityEncrypted()) {
showPasswordDialog.value = true
} else {
// Initialize identity system for non-encrypted identities
try {
await identity.initialize()
} catch (error) {
console.error('Failed to initialize identity:', error)
}
// Initialize authentication
try {
await auth.initialize()
} catch (error) {
console.error('Failed to initialize authentication:', error)
}
// Connect to Nostr relays
await connect()
// Check push notification status
await nostrStore.checkPushNotificationStatus()
})
onUnmounted(() => {
disconnect()
})
</script>
@ -64,6 +34,9 @@ onUnmounted(() => {
<nav
class="w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 xl:px-12 2xl:px-16 flex h-14 lg:h-16 xl:h-20 items-center justify-between">
<Navbar />
<<<<<<< HEAD <ConnectionStatus :is-connected="isConnected" :is-connecting="isConnecting" :error="error" />
=======
>>>>>>> 4686e5e (refactor: Transition to authentication system and remove identity management)
</nav>
</header>
@ -77,9 +50,13 @@ onUnmounted(() => {
<!-- Toast notifications -->
<Toaster />
<!-- Password unlock dialog -->
<PasswordDialog v-model:is-open="showPasswordDialog" title="Unlock Identity"
description="Your Nostr identity is encrypted. Enter your password to unlock it." @password="handlePasswordUnlock"
@cancel="handlePasswordCancel" />
<<<<<<< HEAD <!-- Password unlock dialog -->
<PasswordDialog v-model:is-open="showPasswordDialog" title="Unlock Identity"
description="Your Nostr identity is encrypted. Enter your password to unlock it."
@password="handlePasswordUnlock" @cancel="handlePasswordCancel" />
=======
<!-- Login dialog -->
<LoginDialog v-model:is-open="showLoginDialog" @success="handleLoginSuccess" />
>>>>>>> 4686e5e (refactor: Transition to authentication system and remove identity management)
</div>
</template>