gitfoss-fork-fork | 13976a491350a60931fdee7906562158d629e94f | 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);
    }
  };