PHP 8.2.30
Preview: logout.handler.ts Size: 935 B
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/@adminjs/express/src/authentication/logout.handler.ts

import AdminJS from "adminjs";
import { Router } from "express";
import { AuthenticationOptions } from "../types.js";

const getLogoutPath = (admin: AdminJS) => {
  const { logoutPath, rootPath } = admin.options;
  const normalizedLogoutPath = logoutPath.replace(rootPath, "");

  return normalizedLogoutPath.startsWith("/")
    ? normalizedLogoutPath
    : `/${normalizedLogoutPath}`;
};

export const withLogout = (
  router: Router,
  admin: AdminJS,
  auth: AuthenticationOptions
): void => {
  const logoutPath = getLogoutPath(admin);

  const { provider } = auth;

  router.get(logoutPath, async (request, response) => {
    if (provider) {
      try {
        await provider.handleLogout({ req: request, res: response });
      } catch (error) {
        console.error(error); // fail silently and still logout
      }
    }

    request.session.destroy(() => {
      response.redirect(admin.options.loginPath);
    });
  });
};

Directory Contents

Dirs: 0 × Files: 4

Name Size Perms Modified Actions
4.25 KB lrw-r--r-- 2026-02-28 00:29:04
Edit Download
935 B lrw-r--r-- 2026-02-28 00:29:06
Edit Download
490 B lrw-r--r-- 2026-02-28 00:29:10
Edit Download
1.53 KB lrw-r--r-- 2026-02-28 00:29:10
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).