Auth / foldkit-auth

SSR's posted forms

Forms handled by foldkit-ssr without client JavaScript are standard browser POSTs. SSR.entry's origins check rejects cross-origin form posts with 403 before reading the body, and resources resolves the poster using requests: 'browser':

ts
import { Context, Layer, Option } from 'effect'
import { SSR } from 'foldkit-ssr'

class Principal extends Context.Service<Principal, Option.Option<{ readonly id: string }>>()(
  'app/Principal',
) {}

const whoPosted = AuthServer.resolver({
  requests: 'browser',
  auth: AppAuth,
  http,
  principal: session => Effect.succeed({ id: session.subjectId }),
})

export const entry = SSR.entry(config, plan, {
  buildId: 'b1',
  origins: [http.origin],
  resources: request =>
    Layer.effect(Principal, whoPosted(request)).pipe(Layer.provide(AppAuthLive), Layer.orDie),
})

Because Layer.orDie converts a failed session check into a defect (500), resolve the session in your host before calling renderPage (as Site.access does for 303 redirects) if you want an expired session to redirect to sign-in.