({ request, match, session, isRunningLocally }: RequestHandlerParams)
| 20 | const titlePrefix = 'Multi-Factor Authentication Verification'; |
| 21 | |
| 22 | async function get({ request, match, session, isRunningLocally }: RequestHandlerParams) { |
| 23 | const isMultiFactorAuthEnabled = await AppConfig.isMultiFactorAuthEnabled(); |
| 24 | |
| 25 | if (!isMultiFactorAuthEnabled) { |
| 26 | return new Response('Redirect', { status: 303, headers: { 'Location': '/login' } }); |
| 27 | } |
| 28 | |
| 29 | const searchParams = new URL(request.url).searchParams; |
| 30 | const redirectUrl = searchParams.get('redirect') || '/'; |
| 31 | |
| 32 | const { user } = (await MultiFactorAuthModel.getDataFromRequest(request)) || {}; |
| 33 | |
| 34 | if (!user) { |
| 35 | return new Response('Redirect', { status: 303, headers: { 'Location': '/login' } }); |
| 36 | } |
| 37 | |
| 38 | const hasMultiFactorAuthEnabled = isMultiFactorAuthEnabledForUser(user); |
| 39 | |
| 40 | if (!hasMultiFactorAuthEnabled) { |
| 41 | return new Response('Redirect', { status: 303, headers: { 'Location': '/login' } }); |
| 42 | } |
| 43 | |
| 44 | const enabledMethods = getEnabledMultiFactorAuthMethodsFromUser(user); |
| 45 | const availableMethods = enabledMethods.map((method) => method.type); |
| 46 | |
| 47 | const htmlContent = defaultHtmlContent({ |
| 48 | email: user.email, |
| 49 | redirectUrl, |
| 50 | availableMethods, |
| 51 | }); |
| 52 | |
| 53 | return basicLayoutResponse(htmlContent, { |
| 54 | currentPath: match.pathname.input, |
| 55 | titlePrefix, |
| 56 | match, |
| 57 | request, |
| 58 | session, |
| 59 | isRunningLocally, |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | async function post({ request, match, session, isRunningLocally }: RequestHandlerParams) { |
| 64 | const isMultiFactorAuthEnabled = await AppConfig.isMultiFactorAuthEnabled(); |
nothing calls this directly
no test coverage detected