UNPKG

@clerk/clerk-react

Version:

Clerk.dev React library

27 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SignInButton = void 0; const tslib_1 = require("tslib"); const react_1 = (0, tslib_1.__importDefault)(require("react")); const contexts_1 = require("../contexts"); const utils_1 = require("../utils"); exports.SignInButton = (0, contexts_1.withClerk)((_a) => { var { clerk, children } = _a, props = (0, tslib_1.__rest)(_a, ["clerk", "children"]); const { afterSignInUrl, afterSignUpUrl, redirectUrl, mode } = props, rest = (0, tslib_1.__rest)(props, ["afterSignInUrl", "afterSignUpUrl", "redirectUrl", "mode"]); children = (0, utils_1.normalizeWithDefaultValue)(children, 'Sign in'); const child = (0, utils_1.assertSingleChild)(children)('SignInButton'); const clickHandler = () => { const opts = { afterSignInUrl, afterSignUpUrl, redirectUrl }; if (mode === 'modal') { return clerk.openSignIn(opts); } return clerk.redirectToSignIn(opts); }; const wrappedChildClickHandler = async (e) => { await (0, utils_1.safeExecute)(child.props.onClick)(e); return clickHandler(); }; const childProps = Object.assign(Object.assign({}, rest), { onClick: wrappedChildClickHandler }); return react_1.default.cloneElement(child, childProps); }, 'SignInButton'); //# sourceMappingURL=SignInButton.js.map