diff --git a/app/(dashboard)/skattekonto/page.tsx b/app/(dashboard)/skattekonto/page.tsx index 0052a854..b7c654c4 100644 --- a/app/(dashboard)/skattekonto/page.tsx +++ b/app/(dashboard)/skattekonto/page.tsx @@ -67,6 +67,10 @@ export default function SkattekontoPage() { const [bookingId, setBookingId] = useState(null) const [notConnected, setNotConnected] = useState(false) const [loadError, setLoadError] = useState(false) + // Set when a sync fails with an auth error while a connection exists + // (expired session, missing scope, revoked token). Rendered as a banner — + // the stored data below stays visible and usable. + const [reconnectMessage, setReconnectMessage] = useState(null) const [matchOpenFor, setMatchOpenFor] = useState( null, ) @@ -122,12 +126,28 @@ export default function SkattekontoPage() { }) const json = await res.json() if (!res.ok) { + // 401 covers several distinct auth states (see handleSkvError in the + // skatteverket extension). Only NOT_CONNECTED means "no connection + // exists" — the rest (SESSION_EXPIRED, MISSING_SCOPE, TOKEN_REVOKED, + // …) fire while Inställningar truthfully shows the stored token as + // "Ansluten". Showing the full "inte anslutet"-tomvy for those + // contradicts the settings panel; show the server's actual reason + // with a reconnect CTA instead. if (res.status === 401) { - setNotConnected(true) + if (json.code === 'NOT_CONNECTED') { + setNotConnected(true) + } else { + setReconnectMessage( + typeof json.error === 'string' && json.error + ? json.error + : 'Anslutningen mot Skatteverket behöver förnyas. Anslut igen med BankID.', + ) + } return } throw new Error(json.error || 'Synk misslyckades') } + setReconnectMessage(null) toast({ title: 'Skattekonto synkroniserat', description: `${json.data.booked} bokförda, ${json.data.upcoming} kommande`, @@ -292,6 +312,21 @@ export default function SkattekontoPage() { } /> + {reconnectMessage && ( +
+
+ +

{reconnectMessage}

+
+ +
+ )} + diff --git a/components/settings/sections/TaxSettingsContent.tsx b/components/settings/sections/TaxSettingsContent.tsx index f1cd4af6..f37d8e55 100644 --- a/components/settings/sections/TaxSettingsContent.tsx +++ b/components/settings/sections/TaxSettingsContent.tsx @@ -77,11 +77,14 @@ export function TaxSettingsContent() { return (
+ {/* Connection panel first: the skattekonto and momsdeklaration pages + send users here specifically to (re)connect — below the long tax + form it sat out of view. */} + {showSkatteverket && } + - - {showSkatteverket && }
) }