Skip to content

Cache and centralize UT Direct login-state detection - #179

Merged
spotta85 merged 2 commits into
mainfrom
feature/dap-99-plan-handling-authentication-state
Jul 18, 2026
Merged

Cache and centralize UT Direct login-state detection#179
spotta85 merged 2 commits into
mainfrom
feature/dap-99-plan-handling-authentication-state

Conversation

@spotta85

@spotta85 spotta85 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

We dont know if the user is logged in. We can check but thats slow
#178

Solution

Explicity manage this stuff and cache for performance :)

flowchart LR
    subgraph login-state.ts [login-state.ts — single owner]
        cache[(local:utdLoggedIn<br/>true / false / null)]
        probe[isLoggedIn probe fetch]
    end

    CS[Content script<br/>recordLoginStateFromPage] -->|DOM: login form?| cache
    CK[Cookie watcher<br/>sessionid-degree-audits-production] -->|removed → false<br/>set → verify| cache
    BG[Background runNewAudit] -->|refreshLoginState guard| probe
    POP[Popup] -->|getCachedLoginState → instant paint| cache
    POP -->|refreshLoginState → verify| probe
    cache -->|watchLoginState → live updates| POP
    probe --> cache
Loading

The interface (everything else — probe URL, cookie name, storage key, redirect semantics — is private):

Export Used by Purpose
getCachedLoginState() popup instant paint (ms, may be stale)
refreshLoginState() popup, background live truth + cache write
watchLoginState(cb) popup react to writes from other contexts
recordLoginStateFromPage(doc) content script definitive DOM signal on real UT pages
registerSessionCookieWatcher() background instant invalidation when the session cookie dies
openLoginTab() popup, background the one way to send a user to log in

Behavior

You can basically tell with certainty if user is not logged in or what.
Use the formatting described in teh code -> first check, then do the refresh with the auxillary functions

If the session expires adn coookie not deleted, we kinda fried but tahts why you ahve to check first before doing any action that requires auth.

@linear

linear Bot commented Jul 17, 2026

Copy link
Copy Markdown

DAP-99

@spotta85
spotta85 merged commit 6d79524 into main Jul 18, 2026
8 of 10 checks passed
@spotta85
spotta85 deleted the feature/dap-99-plan-handling-authentication-state branch July 18, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant