Implement onboarding reset functionality and enhance backup features
- Added a new method to reset the onboarding state, allowing users to re-initiate the onboarding process. - Integrated backup creation functionality, enabling users to create encrypted backups of their node identity. - Updated API endpoints to handle onboarding reset and backup creation requests. - Enhanced UI components to support the new onboarding reset and backup features, including error handling and user feedback. - Introduced new dependencies for cryptographic operations and data encoding.
This commit is contained in:
@@ -124,6 +124,22 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
// Session check with timeout - avoids endless spinner on mobile/slow networks
|
||||
const SESSION_CHECK_TIMEOUT_MS = 8000
|
||||
|
||||
async function checkSessionWithTimeout(store: ReturnType<typeof useAppStore>): Promise<boolean> {
|
||||
try {
|
||||
return await Promise.race([
|
||||
store.checkSession(),
|
||||
new Promise<boolean>((resolve) =>
|
||||
setTimeout(() => resolve(false), SESSION_CHECK_TIMEOUT_MS)
|
||||
),
|
||||
])
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigation Guard
|
||||
* Handles authentication and onboarding flow routing
|
||||
@@ -134,16 +150,16 @@ router.beforeEach(async (to, _from, next) => {
|
||||
|
||||
// Allow all public routes (login, onboarding) without auth check
|
||||
if (isPublic) {
|
||||
// If authenticated and visiting /login, validate session first
|
||||
// If authenticated and visiting /login: show login immediately, validate in background.
|
||||
// This prevents endless spinner on mobile when checkSession hangs (slow/unreachable network).
|
||||
if (to.path === '/login' && store.isAuthenticated) {
|
||||
if (store.needsSessionValidation()) {
|
||||
const valid = await store.checkSession()
|
||||
if (valid) {
|
||||
next({ name: 'home' })
|
||||
return
|
||||
}
|
||||
// Session invalid, allow login page
|
||||
next()
|
||||
checkSessionWithTimeout(store).then((valid) => {
|
||||
if (valid) {
|
||||
router.replace({ name: 'home' }).catch(() => {})
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
next({ name: 'home' })
|
||||
@@ -153,9 +169,9 @@ router.beforeEach(async (to, _from, next) => {
|
||||
return
|
||||
}
|
||||
|
||||
// Protected routes: validate session if stale auth from localStorage
|
||||
// Protected routes: validate session if stale auth from localStorage (with timeout)
|
||||
if (store.needsSessionValidation()) {
|
||||
const valid = await store.checkSession()
|
||||
const valid = await checkSessionWithTimeout(store)
|
||||
if (!valid) {
|
||||
next('/login')
|
||||
return
|
||||
@@ -164,9 +180,9 @@ router.beforeEach(async (to, _from, next) => {
|
||||
return
|
||||
}
|
||||
|
||||
// Not authenticated at all
|
||||
// Not authenticated at all (with timeout to avoid endless spinner on mobile)
|
||||
if (!store.isAuthenticated) {
|
||||
const hasSession = await store.checkSession()
|
||||
const hasSession = await checkSessionWithTimeout(store)
|
||||
if (hasSession) {
|
||||
next()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user