UNPKG

payload-totp-temp

Version:

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

26 lines (25 loc) 1.05 kB
/* eslint-disable no-restricted-exports */ 'use client'; import { useAuth } from '@payloadcms/ui'; import { usePathname, useRouter } from 'next/navigation.js'; import { useEffect } from 'react'; export default function TOTPProviderClient(args) { const { children, forceSetup, setupUrl, verifyUrl } = args; const { user } = useAuth(); const router = useRouter(); const pathname = usePathname(); useEffect(()=>{ if (user && user.hasTotp && user._strategy && ![ 'api-key', 'totp' ].includes(user._strategy) && pathname !== verifyUrl) { router.push(`${verifyUrl}?back=${encodeURIComponent(pathname)}`); } else if (user && !user.hasTotp && (user.forceTotp || forceSetup) && pathname !== setupUrl && user._strategy !== 'api-key') { router.push(`${setupUrl}?back=${encodeURIComponent(pathname)}`); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ user ]); return children; } //# sourceMappingURL=index.client.js.map