# 0023 The viewer page asks before it signs in again

Sources: [\#1022](<https://github.com/eizedev/pivotkit/issues/1022>), [\#1031](<https://github.com/eizedev/pivotkit/pull/1031>)

This record supplements [0021](<https://pivotkit.eize.dev/decisions/0021-the-browser-path/index.md>) for the viewer page. 0021 stays binding for everything else, including that the page keeps no session. 0021 is accepted and not edited, so it does not link here, as [0010](<https://pivotkit.eize.dev/decisions/0010-signed-tokens-without-audience/index.md>) does not link the record that amends it.

## Context and Problem Statement

The viewer page (`/live/<source>`) gives the report a browser token that lasts `rest.browser.minutes`. When the report reads again after that, for example after Try again, it needs a new token. The page then has to sign the person in again. 0021 says the page "goes to the provider again on every reload and whenever the report needs a new browser token". The page did that at once.

What a person saw (\#1022): the page left without a word. With a session at the provider it came back after a moment. Without one, the provider's sign-in page appeared in the middle of their work. How should the page ask for the new sign-in?

## Considered Options

- Leave for the provider's sign-in at once: the page as 0021 built it.
- Say that the sign-in ended, keep the rows shown, and sign in again only when the person chooses Sign in again.
- A session in a cookie, 0021's option C.
- A sign-in in the background, where the provider allows it.

## Decision Outcome

Chosen option: say that the sign-in ended and wait for the person. \#1022 proposed it, and \#1031 built it. The reason: the page then no longer takes the person away from their work without a word (\#1022). It needs no session or cookie, so 0021's reasons for having none still hold.

- Leaving at once: not kept, for the reason above.
- A session in a cookie: 0021 lists it as not built and a possible later option. This record does not change that.
- A sign-in in the background: named in \#1022 as needing a decision. Not decided here; reason not recorded.

What the page does:

- Over rows already shown, a banner says "Your sign-in for this report has ended". Its text says that the data could not be refreshed and names the time of the data shown. Its button is **Sign in again**.
- Before any rows came, the same message takes the place of the report.
- The words are the page's own, in English or German.
- The page does not leave on its own. **Sign in again**, or a reload, loads the page again, which signs in as before. No session and no cookie follow, beyond the sign-in under way.
- After that sign-in, the report comes back with the view the person had.
- Another link to the same report with a view of its own, opened later in the same tab, opens with that view. The same address opened again in that tab counts as the reload.
- Only a page that got a browser token carries these words. A refused or failed sign-in's page carries none of them.

What the tab keeps in `sessionStorage`, until the tab closes:

- the link's view (the address's fragment). It never reaches the server and must survive the trip to the provider.
- the last link the tab opened, for the Sign in again of a failed sign-in.
- the view shown, through the element's `persist-view`, so the report can come back with it. It is one entry per tab, not one per link.
- the address the report had when its sign-in ended, only when it showed rows. The next start of the page reads and clears it. When that start is the same address, the page drops the link's view, so the view shown wins. Before any rows came, the person had only the link's view, so it stays.

The addresses are the link's path and query, so they hold the link's parameters and its `pk-access`. `sessionStorage` holds no token and no claim of the person. Where the browser refuses it, as some private windows do, the report opens with the link's view.

### Consequences

- Good: the person sees why the data stopped refreshing. The rows shown stay until they choose to sign in again.
- Good: no session, no cookie and no state on the server.
- Bad: the person needs one click more where the provider would have signed them in without a question.
- Bad: the page's words for this state repeat the element's label keys (`expired`, `expiredData`). A rename in the element drops them without an error. Only the browser test catches it.
- Bad: the view a person shaped lives only in the tab. A new tab, or a private window without storage, opens with the link's view.
