Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/dashboard-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function DashboardFrame({ initialSession }: { initialSession: AdminSessio
if (result.error) throw new Error(result.error.message)
await router.invalidate()
await router.navigate({ to: "/login", replace: true })
} catch {
} catch (error) {
console.error(error)
toast.error("Could not sign out. Please try again.")
setLoggingOut(false)
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/dashboard-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export function DashboardSidebar({ user, loggingOut, onLogout, ...props }: Dashb
try {
const stored = window.localStorage.getItem(categoryStorageKey)
if (stored) setCategoryState(JSON.parse(stored))
} catch {
} catch (error) {
console.error(error)
// Ignore malformed or unavailable local storage and use route-based defaults.
}
}, [])
Expand All @@ -66,7 +67,8 @@ export function DashboardSidebar({ user, loggingOut, onLogout, ...props }: Dashb
const next = { ...current, [title]: open }
try {
window.localStorage.setItem(categoryStorageKey, JSON.stringify(next))
} catch {
} catch (error) {
console.error(error)
// The in-memory state still works when storage is unavailable.
}
return next
Expand Down
4 changes: 3 additions & 1 deletion src/components/telegram/create-grant-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,16 @@ export function CreateGrantDialog({ user: fixedUser }: CreateGrantDialogProps) {
data: { userId: selectedUser.id, since, until, reason: reason.trim() || undefined },
})
if (result.error) {
console.error(result.error)
toast.error(grantMutationError(result.error))
return
}
toast.success(`Grant created for ${displayName(selectedUser)}.`)
closeAndReset()
try {
await router.invalidate({ sync: true })
} catch {
} catch (error) {
console.error(error)
toast.warning("The grant was created, but the latest grants could not be refreshed.")
}
} catch (error) {
Expand Down
56 changes: 38 additions & 18 deletions src/features/account/use-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ export function useAccount(initialSession: AdminSession) {
try {
const [passkeyResult, sessionResult] = await Promise.all([auth.passkey.listUserPasskeys(), auth.listSessions()])
if (passkeyResult.error || sessionResult.error) {
if (passkeyResult.error) console.error(passkeyResult.error)
if (sessionResult.error) console.error(sessionResult.error)
setSecurityError("Could not load passkeys and active sessions. Your existing security data is still shown.")
return false
}
setPasskeys(passkeyResult.data ?? [])
setSessions(sessionResult.data ?? [])
setSecurityError("")
return true
} catch {
} catch (error) {
console.error(error)
setSecurityError("Could not load passkeys and active sessions. Your existing security data is still shown.")
return false
} finally {
Expand All @@ -58,12 +61,15 @@ export function useAccount(initialSession: AdminSession) {
setNotice(null)
try {
const result = await auth.updateUser({ name: name.trim() })
if (result.error) setNotice({ type: "error", text: result.error.message ?? "Could not update your name." })
else {
if (result.error) {
console.error(result.error)
setNotice({ type: "error", text: result.error.message ?? "Could not update your name." })
} else {
await sessionQuery.refetch()
setNotice({ type: "success", text: "Profile name updated." })
}
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not update your name." })
} finally {
setBusy(null)
Expand All @@ -85,7 +91,8 @@ export function useAccount(initialSession: AdminSession) {
await uploadProfilePictureFn({ data: formData })
await sessionQuery.refetch()
setNotice({ type: "success", text: "Profile picture updated." })
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not update your profile picture." })
}
setBusy(null)
Expand All @@ -96,12 +103,15 @@ export function useAccount(initialSession: AdminSession) {
setNotice(null)
try {
const result = await auth.updateUser({ image: null })
if (result.error) setNotice({ type: "error", text: result.error.message ?? "Could not remove the picture." })
else {
if (result.error) {
console.error(result.error)
setNotice({ type: "error", text: result.error.message ?? "Could not remove the picture." })
} else {
await sessionQuery.refetch()
setNotice({ type: "success", text: "Profile picture removed." })
}
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not remove the picture." })
} finally {
setBusy(null)
Expand All @@ -113,15 +123,18 @@ export function useAccount(initialSession: AdminSession) {
setNotice(null)
try {
const result = await auth.passkey.addPasskey({ name: `Passkey ${passkeys.length + 1}` })
if (result.error) setNotice({ type: "error", text: result.error.message ?? "Could not create the passkey." })
else {
if (result.error) {
console.error(result.error)
setNotice({ type: "error", text: result.error.message ?? "Could not create the passkey." })
} else {
const refreshed = await refreshSecurityData()
setNotice({
type: "success",
text: refreshed ? "Passkey created." : "Passkey created. Refresh security data to see the updated list.",
})
}
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not create the passkey." })
} finally {
setBusy(null)
Expand All @@ -133,15 +146,18 @@ export function useAccount(initialSession: AdminSession) {
setNotice(null)
try {
const result = await auth.passkey.deletePasskey({ id })
if (result.error) setNotice({ type: "error", text: result.error.message ?? "Could not delete the passkey." })
else {
if (result.error) {
console.error(result.error)
setNotice({ type: "error", text: result.error.message ?? "Could not delete the passkey." })
} else {
const refreshed = await refreshSecurityData()
setNotice({
type: "success",
text: refreshed ? "Passkey deleted." : "Passkey deleted. Refresh security data to see the updated list.",
})
}
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not delete the passkey." })
} finally {
setBusy(null)
Expand All @@ -153,8 +169,10 @@ export function useAccount(initialSession: AdminSession) {
setNotice(null)
try {
const result = await auth.revokeOtherSessions()
if (result.error) setNotice({ type: "error", text: result.error.message ?? "Could not revoke other sessions." })
else {
if (result.error) {
console.error(result.error)
setNotice({ type: "error", text: result.error.message ?? "Could not revoke other sessions." })
} else {
const refreshed = await refreshSecurityData()
setNotice({
type: "success",
Expand All @@ -163,7 +181,8 @@ export function useAccount(initialSession: AdminSession) {
: "Sessions were signed out. Refresh security data to see the updated list.",
})
}
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not revoke other sessions." })
} finally {
setBusy(null)
Expand All @@ -178,7 +197,8 @@ export function useAccount(initialSession: AdminSession) {
if (result.error) throw new Error(result.error.message)
await router.invalidate()
await router.navigate({ to: "/login", replace: true })
} catch {
} catch (error) {
console.error(error)
setNotice({ type: "error", text: "Could not sign out. Please try again." })
setBusy(null)
}
Expand Down
Loading
Loading