Skip to content

fix(SessionService): Disabling sign-in never signs anyone out, because the renewal answer is read as JSON - #2382

Open
Isaries wants to merge 1 commit into
WISE-Community:developfrom
Isaries:fix/session-renew-text
Open

Isaries wants to merge 1 commit into
WISE-Community:developfrom
Isaries:fix/session-renew-text

Conversation

@Isaries

@Isaries Isaries commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

When an administrator disables sign-in, nobody who is already signed in is signed out. /api/session/renew answers in plain text: true, false, or requestLogout when sign-in has been disabled. SessionService.checkIfSessionIsActive() requests it with http.get<boolean>, so requestLogout fails to parse as JSON, the error is not handled, and the user stays on the page as if nothing had happened.

Disabling sign-in is how an administrator clears the site before maintenance, so the people it is meant to reach are exactly the ones still working.

Making the client act on requestLogout has a cost that this change avoids. Signing out goes through logOut(), which does not save, so a student in the middle of a step would lose whatever has not been auto-saved yet. Unlike an ended session, the session is still valid at this point and can save, so the work is saved first.

Changes

  • checkSession() replaces checkIfSessionIsActive(), reads the answer as text and maps it to active, ended, closed, or unknown. ended signs out as before; an empty or unexpected answer keeps the user signed in.
  • registerExitSaver() lets a component register a save to run before a closed site signs the user out. NodeComponent registers one that stops auto-save and saves its unsaved components with the same createAndSaveComponentData(true) call auto-save uses.
  • On closed, the registered saves run, with at most ten seconds to finish so that a save that never answers does not keep the user in, and the user is then signed out and sent to /login?loginDisabled=true. If the sign-out request fails, the next renewal tries again, because the sign-in page would send a user whose session is still valid back into the unit.

Related changes, each in its own PR:

  • WISE-API#371 is needed before this one: renewal currently answers requestLogout to administrators too, so without it this change signs out the administrator who closed the site.
  • WISE-Client#2381 shows why the user was signed out on /login?loginDisabled=true.
  • WISE-API#369 and WISE-API#370 fix the sign-in refusal and the renewal of an ended session on the backend.

Test

  • New cases in sessionService.spec.ts drive renewSession() through HttpTestingController with each answer the server sends, and cover the closed-site path: saving before signing out, signing out after ten seconds when a save never answers, a save that has been unregistered, a save that throws, retrying when the sign-out request fails, and the same path from an idle session. Against the current develop the closed-site case fails with Expected one matching request for criteria "Match URL: /api/logout", found none.
  • sessionService.spec.ts and all specs under vle pass (58). In the full suite the only failure is millisecondsToDateTime(), which depends on the machine's time zone and fails the same way without this change.

…e the renewal answer is read as JSON

/api/session/renew answers in plain text: "true", "false", or
"requestLogout" when sign-in has been disabled. checkIfSessionIsActive()
requests it as JSON, so "requestLogout" is a parse error and nobody who
is already signed in is signed out when an administrator disables
sign-in. The answer is now read as text and mapped to a session state.

Signing out goes through logOut(), which does not save, so acting on
"requestLogout" directly would discard a student's unsaved work, even
though the session is still valid at that point and can save. Components
can now register a save with registerExitSaver(); NodeComponent registers
one that saves its unsaved components. When sign-in is disabled, the
registered saves run, with at most ten seconds to finish, and the user
is then signed out and sent to /login?loginDisabled=true. If the
sign-out request fails, the next renewal tries again.
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