import { Request , Response } from "@architect/shared/architect-types" ; import { log , ObjectLiteral , stringify } from "@architect/shared/utils" ; import arc from "@architect/functions" ; import redirect from "@architect/shared/redirect" ; import { authenticateWithEmail } from "@architect/shared/authentication" ; async function handler ( request ) { const body = request . body as ObjectLiteral ; const { email , password } = body ; log ( { email , password } ) ; const person = await authenticateWithEmail ( email , password ) ; if ( ! person ) { log ( `Invalid login attempt for ${ email }` ) ; return redirect ( "/login" ) ; } const cookie = await arc . http . session . write ( { person } ) ; log ( `Attached a person ${ person . _id } to the session.` ) ; return redirect ( "/" , cookie ) ; } exports . handler = arc . http . async ( handler ) ;