ekyc

Electronic KYC process with uploading ID document using OAuth 2.1 (experimental)
Log | Files | Refs | README | LICENSE

_middleware.ts (659B)


      1 import { app } from "#http/app.ts";
      2 import { FormContexts, Forms } from "#http/form.ts";
      3 import { FreshContext } from "$fresh/server.ts";
      4 
      5 export type AppState<F extends keyof FormContexts = keyof FormContexts> = {
      6   app: typeof app;
      7   forms: Forms;
      8   formContext: FormContexts[F] | null;
      9 };
     10 
     11 export async function handler(req: Request, ctx: FreshContext<AppState>) {
     12   // Inject http in context
     13   ctx.state.app = app;
     14 
     15   // Authenticate Form
     16   ctx.state.forms = await Forms.parse(req, app.authSession);
     17 
     18   // Parse form context
     19   ctx.state.formContext = ctx.state.forms.context(
     20     ctx.state.forms.base.pathname as never,
     21   );
     22 
     23   return await ctx.next();
     24 }