UNPKG

payload-totp-temp

Version:

Add an extra security layer to PayloadCMS using a Time-based One-time Password (TOTP).

38 lines (37 loc) 1.5 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { formatAdminURL } from '@payloadcms/ui/shared'; import { headers } from 'next/headers.js'; import { redirect } from 'next/navigation.js'; import TOTPProviderClient from './index.client.js'; export const TOTPProvider = async (args)=>{ const { children, payload, pluginOptions, user: _user } = args; const user = _user; const headersList = await headers(); const pathname = headersList.get('x-pathname'); const verifyUrl = formatAdminURL({ adminRoute: payload.config.routes.admin, path: '/verify-totp', serverURL: payload.config.serverURL }); const setupUrl = formatAdminURL({ adminRoute: payload.config.routes.admin, path: '/setup-totp', serverURL: payload.config.serverURL }); if (user && user.hasTotp && ![ 'api-key', 'totp' ].includes(user._strategy) && pathname !== verifyUrl) { redirect(`${verifyUrl}?back=${encodeURIComponent(pathname)}`); } else if (user && !user.hasTotp && (user.forceTotp || pluginOptions.forceSetup) && pathname !== setupUrl && user._strategy !== 'api-key') { redirect(`${setupUrl}?back=${encodeURIComponent(pathname)}`); } else { return /*#__PURE__*/ _jsx(TOTPProviderClient, { forceSetup: pluginOptions.forceSetup, setupUrl: setupUrl, verifyUrl: verifyUrl, children: children }); } }; //# sourceMappingURL=index.js.map