gitfoss-fork-fork | 69a27d85b5b6c9a048c3e73593a35ba336ad1571 | app/utils/server/authenticatedOrRedirect.ts ∙ GitFOSS
.ts
TypeScript
(application/typescript)
import type { preHandlerHookHandler } from "fastify";

export const authenticatedOrRedirect =
  (redirectToPath: string, statusCode: number = 302): preHandlerHookHandler =>
  async (request, reply) => {
    if (request.session.data.authenticated === false) {
      reply.redirect(statusCode, redirectToPath);
    }
  };