UNPKG

payload-authjs

Version:
36 lines (35 loc) 1.34 kB
"use client"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Button, useAuth, useDocumentInfo } from "@payloadcms/ui"; import { signIn } from "next-auth/webauthn"; import { AUTHJS_STRATEGY_NAME } from "../../constants"; /** * A button in the admin panel to add an authenticator using Auth.js * * @see https://authjs.dev/getting-started/authentication/webauthn */ export const AddAuthenticatorButton = ({ provider })=>{ const { collectionSlug, id } = useDocumentInfo(); const { user } = useAuth(); if (!user || // Check if the current document belongs to the user user.collection !== collectionSlug || user.id !== id || // Register a new authenticator is only allowed if the user has a valid Auth.js session user._strategy !== AUTHJS_STRATEGY_NAME) { return; } return /*#__PURE__*/ _jsx("div", { children: /*#__PURE__*/ _jsxs(Button, { buttonStyle: "secondary", onClick: async (e)=>{ e.preventDefault(); await signIn(provider.id, { action: "register" }); }, children: [ "Add Authenticator (", provider.name, ")" ] }) }); }; //# sourceMappingURL=AddAuthenticatorButton.js.map