Atomic Angular — Doc interne

Warn before the session expires

Tell the user shortly before their session expires, and when it already has, whatever way they signed in.

provideSessionExpiry() raises a warning toast shortly before the session ends, and an error toast — with a "Sign in again" action — when the backend says it has. Both are notify events, rendered by your application's toast bridge.

Session

The server-side state that says the user is signed in. Its lifetime is the backend's setting, not the library's: some backends end it a fixed time after sign-in, others push it forward as the user works.

Minimal example

Registered next to the client and the failed-request toasts
app.config.ts
import { ApplicationConfig } from "@angular/core";
import { provideAtomicClient, provideAtomicNotifications, provideSessionExpiry } from "@sinequa/atomic-angular";

export const appConfig: ApplicationConfig = {
  providers: [provideAtomicClient({ app: "my-app" }), provideAtomicNotifications(), provideSessionExpiry()],
};

How it works

Two independent signals, because no single one works for every way of signing in.

Proactive. The token @sinequa/atomic stores — the csrfToken of the sign-in and challenge responses, and the sinequa-jwt-refresh header — looks like <opaque token>|<epoch in seconds>, and the suffix is the expiry of the session. It is the only expiry date a browser can read, since the session cookie is HttpOnly. The provider reads it at start-up and on every tokenRefreshed, and schedules the warning warnBeforeMs before it. The warning is raised once: it is armed again only when a renewal takes the expiry back out of that window.

Reactive. A 401 that reaches its caller on a session that had been established means it is gone, whatever the sign-in, and raises the error toast once. The provider follows the client's sessionLost event (@sinequa/atomic 2.8 or later), not unauthorized: unauthorized fires as soon as the 401 is read, before the recovery that bootstrapApp installs gets its chance, so a session it re-establishes silently (single sign-on) would be announced lost. The client already leaves out the 401s that are answers rather than expiries — the sign-in, the start-up probe, audit events — and the requests trailing behind a logout. Requests sent with HttpClient, which the client never sees, are covered by errorInterceptorFn when its own recovery gives up. A 401 while a user is impersonated is left to its own message in provideAtomicNotifications().

response carrying the token and its expiry tokenRefreshed schedule the warning at expiry minus warnBeforeMs notify.warning 401 on an established session recoverFromUnauthorized, the request replayed once sessionLost, only if the session could not be re-established notify.error with a Sign in again action Backend Atomic client provideSessionExpiry Toast bridge

The texts live in the session-expiry Transloco scope, extracted into your application like the library's other scopes (transloco-scoped-libs). Without Transloco, or when the scope was not extracted, the English texts built into the provider are used instead of a raw key.

The token format is not a documented contract

The |<epoch> suffix is what the backends observed so far send, not something Sinequa promises. When a token has no readable suffix — a backend that sends bare tokens, or an ambient single sign-on that leaves no token at all — the proactive warning simply never arms, and the reactive toast still works. Nothing is shown that the provider is not sure of.

Recipes

Warn two minutes ahead and send the user to your own sign-in page
app.config.ts
import { ApplicationConfig } from "@angular/core";
import { provideAtomicClient, provideAtomicNotifications, provideSessionExpiry } from "@sinequa/atomic-angular";

export const appConfig: ApplicationConfig = {
  providers: [
    provideAtomicClient({ app: "my-app" }),
    provideAtomicNotifications(),
    provideSessionExpiry({
      warnBeforeMs: 2 * 60_000,
      // 30 s instead of "never closes": see the pitfall about the toast duration
      expiredDuration: 30_000,
      onReconnect: () => window.location.assign("/login"),
    }),
  ],
};

Options

Prop

Type

Pitfalls

What's next

On this page