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