APPNETOS is under active development This website and its documentation are being prepared for public launch. Content and features may change.
Select Theme
Loading

Session Indicator Line

Make session expiration visible. A reusable, color-coded countdown indicator that helps users understand how much time remains in their authenticated session.

Purpose

Session Indicator Line is a reusable APPNETOS Core App that displays the remaining session lifetime as a narrow visual line. Its appearance changes as the configured session timeout approaches: from Bootstrap success to warning and finally danger.

Instead of implementing session indicators separately in every application, developers can reuse the Core App and provide only the context-specific timeout and, if necessary, the desired rendering destination.

Session lifecycle and sign-out

The Core App provides the frontend with the configured timeout, the concrete runtime class and the context URL required for AJAX communication. Its frontend workflow is designed to calculate the remaining session time, update the indicator state, detect expiration and account for browser visibility changes.

State Visual feedback
Session has sufficient time remaining bg-success
Session is approaching expiration bg-warning
Session is close to expiration bg-danger

The exact percentage thresholds and countdown behavior belong to the frontend implementation and are not defined in the PHP controller.

Does it sign out automatically?

The Core App exposes a protected AJAX action, signOut(), that explicitly calls the shared authentication controller's logout() method and returns a successful JSON response. The frontend session workflow also provides automatic expiration detection and page reload behavior.

Important distinction: when the server-side session has already expired, the protected AJAX sign-out request may no longer be processed. The frontend is designed to reload the page in that case, allowing the application's authentication and access-control flow to handle the expired session. The precise request sequence at timeout must be verified against the deployed JavaScript implementation.

Session Indicator Line provides visibility and sign-out behavior; access protection for subsequent content is the responsibility of the application's authentication flow, for example the Force Sign In Core App.

Integration

Extend CoreApp\Security\SessionIndicatorLine in your application context. The Core App initializes its timeout, registers its JavaScript and CSS assets and renders a Bootstrap-specific Twig template. Your implementation can return the view directly or attach it to an existing view slot.

For example, appnetos-dns-control appends the generated indicator to frameset_top so it appears in the upper application layout without rendering duplicate inline output.

use Core\Annotation\Autowire;
use Core\Render\ViewSlotRegistry;
use CoreApp\Security\SessionIndicatorLine as CoreSessionIndicatorLine;

class SessionIndicatorLine extends CoreSessionIndicatorLine
{
    #[Autowire(ViewSlotRegistry::class)]
    protected ViewSlotRegistry $_viewSlotRegistry;

    public function __invoke(): string|null
    {
        $view = parent::__invoke();

        if ($view === null) {
            return null;
        }

        $this->_viewSlotRegistry->append('frameset_top', $view);

        return null;
    }

    protected function getSessionTimeout(): int|null
    {
        return $this->_config->getAdminSessionTimeout() ?? 3600;
    }
}

The example follows the APPNETOS DNS Control integration. The fallback of 3,600 seconds is application-specific, not a default supplied by the shared Core App.

Override methods

The following methods provide the principal integration and customization points. The shared implementation can be reused without replacing its session-handling workflow.

Method When and why to override
protected function getSessionTimeout(): int|null Required: provide the session timeout in seconds for the active application context. The base implementation returns null, which causes initialization to throw SessionIndicatorLineException.
public function __invoke(): ViewSlot|string|null Customize where the generated view is rendered. Call parent::__invoke() to retain timeout initialization and asset registration, then return the view or append it to a view slot.
protected function getBaseTemplate(): string Replace the default Bootstrap-specific Twig template with an application-specific indicator template.
protected function addScriptsAndStyles(): void Adjust the registered frontend assets. Call the parent implementation if the shared countdown and sign-out behavior must remain available.

Additional protected template-resolution helpers exist, including getBootstrapTemplateDirectory() and normalizeBootstrapTemplateVersion(). These are implementation details rather than the usual application-level customization points.

Requirements and implementation notes

  • A concrete implementation must supply a non-null session timeout.
  • The shared template uses the configured Bootstrap version; the provided resolver supports Bootstrap 5.3.
  • The shared Core App registers its minified JavaScript and CSS resources through APPNETOS.
  • The rendered template initially contains an indicator line with bg-success and exports the runtime class and timeout to JavaScript.
  • Session expiration and authentication enforcement should be coordinated with the application's sign-in protection.

Source

appnetos/shared/apps/security/session-indicator-line/src/SessionIndicatorLine.php

Application example: AppnetosDnsControl\Admin\SessionIndicatorLine

Next Steps

Previous

Force Sign In

Explore Force Sign In

Next

Navigation

Explore Navigation