@clerk/clerk-react
Advanced tools
Comparing version 1.6.0 to 1.6.1-staging.0
@@ -69,3 +69,3 @@ 'use strict'; | ||
var version = "1.6.0"; | ||
var version = "1.6.1-staging.0"; | ||
@@ -143,2 +143,3 @@ var FAILED_TO_LOAD_ERROR = 'Clerk: Failed to load Clerk'; | ||
this.premountUserButtonNodes = new Map(); | ||
this.premountMethodCalls = new Map(); | ||
this._loaded = false; | ||
@@ -183,2 +184,6 @@ this.ssrData = null; | ||
_this.premountMethodCalls.forEach(function (cb) { | ||
return cb(); | ||
}); | ||
_this._loaded = true; | ||
@@ -315,2 +320,58 @@ return Promise.resolve(_this.clerkjs); | ||
this.navigate = function (to) { | ||
var callback = function callback() { | ||
var _this2$clerkjs; | ||
return (_this2$clerkjs = _this2.clerkjs) === null || _this2$clerkjs === void 0 ? void 0 : _this2$clerkjs.navigate(to); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('navigate', callback); | ||
} | ||
}; | ||
this.redirectToSignIn = function () { | ||
var callback = function callback() { | ||
var _this2$clerkjs2; | ||
return (_this2$clerkjs2 = _this2.clerkjs) === null || _this2$clerkjs2 === void 0 ? void 0 : _this2$clerkjs2.redirectToSignIn(); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('redirectToSignIn', callback); | ||
} | ||
}; | ||
this.redirectToSignUp = function () { | ||
var callback = function callback() { | ||
var _this2$clerkjs3; | ||
return (_this2$clerkjs3 = _this2.clerkjs) === null || _this2$clerkjs3 === void 0 ? void 0 : _this2$clerkjs3.redirectToSignUp(); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('redirectToSignUp', callback); | ||
} | ||
}; | ||
this.redirectToUserProfile = function () { | ||
var callback = function callback() { | ||
var _this2$clerkjs4; | ||
return (_this2$clerkjs4 = _this2.clerkjs) === null || _this2$clerkjs4 === void 0 ? void 0 : _this2$clerkjs4.redirectToUserProfile(); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('redirectToUserProfile', callback); | ||
} | ||
}; | ||
this.frontendApi = frontendApi; | ||
@@ -732,2 +793,23 @@ this.options = options; | ||
}, 'ClerkLoaded'); | ||
var RedirectToSignIn = /*#__PURE__*/withClerk(function (_ref11) { | ||
var clerk = _ref11.clerk; | ||
React__default.useEffect(function () { | ||
clerk.redirectToSignIn(); | ||
}, []); | ||
return null; | ||
}, 'RedirectToSignIn'); | ||
var RedirectToSignUp = /*#__PURE__*/withClerk(function (_ref12) { | ||
var clerk = _ref12.clerk; | ||
React__default.useEffect(function () { | ||
clerk.redirectToSignUp(); | ||
}, []); | ||
return null; | ||
}, 'RedirectToSignUp'); | ||
var RedirectToUserProfile = /*#__PURE__*/withClerk(function (_ref13) { | ||
var clerk = _ref13.clerk; | ||
React__default.useEffect(function () { | ||
clerk.redirectToUserProfile(); | ||
}, []); | ||
return null; | ||
}, 'redirectToUserProfile'); | ||
@@ -737,2 +819,5 @@ exports.ClerkContext = ClerkContext; | ||
exports.ClerkProvider = ClerkProvider; | ||
exports.RedirectToSignIn = RedirectToSignIn; | ||
exports.RedirectToSignUp = RedirectToSignUp; | ||
exports.RedirectToUserProfile = RedirectToUserProfile; | ||
exports.SignIn = SignIn; | ||
@@ -739,0 +824,0 @@ exports.SignUp = SignUp; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("react"),n=(e=r)&&"object"==typeof e&&"default"in e?e.default:e;function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function o(e,r){e.prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r}function s(e,r){if(null==e)return{};var n,t,o={},s=Object.keys(e);for(t=0;t<s.length;t++)r.indexOf(n=s[t])>=0||(o[n]=e[n]);return o}function i(){return"undefined"!=typeof window}var l="Clerk: You must wrap your application in a <ClerkProvider> component.",u=function(){function e(e,r,n){var t=this,o=this;void 0===r&&(r={}),this.listeners=[],this.clerkjs=null,this.preopenSignIn=null,this.preopenSignUp=null,this.premountSignInNodes=new Map,this.premountSignUpNodes=new Map,this.premountUserProfileNodes=new Map,this.premountUserButtonNodes=new Map,this._loaded=!1,this.ssrData=null,this.hydrateClerkJS=function(e){try{if(!e)throw new Error("Failed to hydrate latest Clerk JS");return o.clerkjs=e,o.listeners.forEach((function(r){e.addListener(r)})),null!==o.preopenSignIn&&e.openSignIn(o.preopenSignIn),null!==o.preopenSignUp&&e.openSignUp(o.preopenSignUp),o.premountSignInNodes.forEach((function(r,n){e.mountSignIn(n,r)})),o.premountSignUpNodes.forEach((function(r,n){e.mountSignUp(n,r)})),o.premountUserProfileNodes.forEach((function(r,n){e.mountUserProfile(n,r)})),o.premountUserButtonNodes.forEach((function(r,n){e.mountUserButton(n,r)})),o._loaded=!0,Promise.resolve(o.clerkjs)}catch(e){return Promise.reject(e)}},this.setSession=function(e,r){return t.clerkjs?t.clerkjs.setSession(e,r):Promise.reject()},this.openSignIn=function(e){t.clerkjs&&t._loaded?t.clerkjs.openSignIn(e):t.preopenSignIn=e},this.closeSignIn=function(){t.clerkjs&&t._loaded?t.clerkjs.closeSignIn():t.preopenSignIn=null},this.openSignUp=function(e){t.clerkjs&&t._loaded?t.clerkjs.openSignUp(e):t.preopenSignUp=e},this.closeSignUp=function(){t.clerkjs&&t._loaded?t.clerkjs.closeSignUp():t.preopenSignUp=null},this.mountSignIn=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountSignIn(e,r):t.premountSignInNodes.set(e,r)},this.unmountSignIn=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountSignIn(e):t.premountSignInNodes.delete(e)},this.mountSignUp=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountSignUp(e,r):t.premountSignUpNodes.set(e,r)},this.unmountSignUp=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountSignUp(e):t.premountSignUpNodes.delete(e)},this.mountUserProfile=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountUserProfile(e,r):t.premountUserProfileNodes.set(e,r)},this.unmountUserProfile=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountUserProfile(e):t.premountUserProfileNodes.delete(e)},this.mountUserButton=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountUserButton(e,r):t.premountUserButtonNodes.set(e,r)},this.unmountUserButton=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountUserButton(e):t.premountUserButtonNodes.delete(e)},this.addListener=function(e){t.clerkjs?t.clerkjs.addListener(e):t.listeners.push(e)},this.loadFromServer=function(e){"browser"===t.mode&&t.throwError("loadFromServer cannot be called in a browser context."),t.ssrData=JSON.stringify({client:t.client,session:t.session,token:e})},this.frontendApi=e,this.options=r,this.ClerkConstructor=n,this.mode=i()?"browser":"server"}var r,n=e.prototype;return n.loadClerkJS=function(){var e,r,n=this;return this.frontendApi?this.ClerkConstructor?(window.Clerk=new this.ClerkConstructor(this.frontendApi),window.Clerk.load(this.options).then((function(){return n.hydrateClerkJS(window.Clerk)})).catch((function(e){return n.throwError(e.message||e)}))):(e=this.frontendApi,r=this.options.scriptUrl,new Promise((function(n,t){window.Clerk&&n(null),e||t("Clerk: Missing provider");var o=document.createElement("script"),s=function(e,r){if(r)return r;var n=function(e){return e.endsWith(".lclstage.dev")||e.endsWith(".stgstage.dev")||e.endsWith(".clerkstage.dev")}(e)?"staging":parseInt("1.6.0".split(".")[0],10);return"https://"+e+"/npm/@clerk/clerk-js@"+n+"/dist/clerk.browser.js"}(e,r);o.setAttribute("data-clerk-frontend-api",e),o.setAttribute("crossorigin","anonymous"),o.async=!0,document.body||t("Clerk: Missing <body> element."),o.addEventListener("load",(function(){return n(o)})),o.addEventListener("error",(function(){return t("Clerk: Failed to load Clerk")})),o.src=s,document.body.appendChild(o)}))).then((function(){if(window.Clerk)return window.Clerk.load(n.options);throw new Error("Failed to download latest Clerk JS")})).then((function(){return n.hydrateClerkJS(window.Clerk)})).catch((function(e){return n.throwError(e.message||e)})):(this.throwError("Clerk: You must add the frontendApi prop to your <ClerkProvider>"),Promise.resolve())},n.throwError=function(e){return console.error(e),Promise.resolve()},(r=[{key:"client",get:function(){return this.clerkjs?this.clerkjs.client:void 0}},{key:"session",get:function(){return this.clerkjs?this.clerkjs.session:void 0}},{key:"user",get:function(){return this.clerkjs?this.clerkjs.user:void 0}},{key:"environment",get:function(){return this.clerkjs?this.clerkjs.environment:void 0}}])&&function(e,r){for(var n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}(e.prototype,r),e}(),c=n.createContext(void 0);c.displayName="ClerkContext";var a=function(e){function r(r){var n;(n=e.call(this,r)||this).onClerkEvent=function(e){n.setState({client:e.client,session:e.session,user:e.user})};var t=r.frontendApi,o=void 0===t?"":t,i=r.Clerk,l=s(r,["frontendApi","Clerk"]);return n.clerk=new u(o,l,i),n.state={client:void 0,session:void 0,user:void 0},n}o(r,e);var t=r.prototype;return t.loadClerk=function(){var e=this;this.clerk.loadClerkJS().then((function(){e.setState({client:e.clerk.client,session:e.clerk.session,user:e.clerk.user})}))},t.componentDidMount=function(){this.loadClerk(),this.clerk&&this.clerk.addListener(this.onClerkEvent)},t.defaultInitialUser=function(e){var r=e.sessions.find((function(e){return"active"===e.status}));return r?r.user:null},t.render=function(){var e=this.state.session;return n.createElement(c.Provider,{value:{guaranteedLoaded:!1,guaranteedUser:!1,clerk:this.clerk}},this.clerk instanceof u&&this.clerk.ssrData&&n.createElement("script",{type:"application/json","data-clerk":"SSR",dangerouslySetInnerHTML:{__html:this.clerk.ssrData}}),n.createElement(n.Fragment,{key:e?e.id:"no-usrses"},this.props.children))},r}(n.PureComponent),d=function(e,o){e.displayName=o=o||e.displayName||e.name||"Component";var s=function(o){var s=r.useContext(c);if(s)return s.clerk&&void 0===s.clerk.session?null:s.guaranteedLoaded?n.createElement(e,Object.assign({},o,{clerk:s.clerk})):s.clerk.client?n.createElement(c.Provider,{value:t({},s,{guaranteedLoaded:!0})},n.createElement(e,Object.assign({},o,{clerk:s.clerk}))):null;if(i())throw new Error(l);return null};return s.displayName="withClerk("+o+")",s},p=function(e,o){e.displayName=o=o||e.displayName||e.name||"Component";var s=function(o){var s=r.useContext(c);if(s)return s.guaranteedUser&&s.clerk.session?n.createElement(e,Object.assign({},o,{user:s.clerk.session.user})):s.clerk.client&&s.clerk.session?n.createElement(c.Provider,{value:t({},s,{guaranteedLoaded:!0,guaranteedUser:!0})},n.createElement(e,Object.assign({},o,{user:s.clerk.session.user}))):null;if(i())throw new Error(l);return null};return s.displayName="withUser("+o+")",s},f=function(e){function r(){var r;return(r=e.apply(this,arguments)||this).portalRef=n.createRef(),r}o(r,e);var t=r.prototype;return t.componentDidMount=function(){this.portalRef.current&&this.props.mount(this.portalRef.current,this.props.props)},t.componentWillUnmount=function(){this.portalRef.current&&this.props.unmount(this.portalRef.current)},t.render=function(){return n.createElement("div",{ref:this.portalRef})},r}(n.PureComponent),k=d((function(e){var r=e.clerk,t=s(e,["clerk"]);return n.createElement(f,{mount:r.mountSignIn,unmount:r.unmountSignIn,props:t})}),"SignIn"),h=d((function(e){var r=e.clerk,t=s(e,["clerk"]);return n.createElement(f,{mount:r.mountSignUp,unmount:r.unmountSignUp,props:t})}),"SignUp"),m=d((function(e){var r=e.clerk,t=s(e,["clerk"]);return n.createElement(f,{mount:r.mountUserProfile,unmount:r.unmountUserProfile,props:t})}),"UserProfile"),g=d((function(e){var r=e.clerk,t=s(e,["clerk"]);return n.createElement(f,{mount:r.mountUserButton,unmount:r.unmountUserButton,props:t})}),"UserButton"),v=p((function(e){return n.createElement(n.Fragment,null,e.children)}),"SignedIn"),C=d((function(e){return null===e.clerk.session?n.createElement(n.Fragment,null,e.children):null}),"SignedOut"),S=d((function(e){return n.createElement(n.Fragment,null,e.children)}),"ClerkLoaded");exports.ClerkContext=c,exports.ClerkLoaded=S,exports.ClerkProvider=a,exports.SignIn=k,exports.SignUp=h,exports.SignedIn=v,exports.SignedOut=C,exports.UserButton=g,exports.UserProfile=m,exports.WithClerk=function(e){var r=e.children;return n.createElement(c.Consumer,null,(function(e){if("function"==typeof r){if(e)return e.clerk&&void 0===e.clerk.session?null:e.guaranteedLoaded?r(e.clerk):e.clerk.client?n.createElement(c.Provider,{value:t({},e,{guaranteedLoaded:!0})},r(e.clerk)):null;throw new Error(l)}throw new Error("Clerk: Child of WithClerk must be a function.")}))},exports.WithUser=function(e){var r=e.children;return n.createElement(c.Consumer,null,(function(e){if("function"==typeof r){if(e)return e.guaranteedUser&&e.clerk.session?r(e.clerk.session.user):e.clerk.client&&e.clerk.session?n.createElement(c.Provider,{value:t({},e,{guaranteedLoaded:!0,guaranteedUser:!0})},r(e.clerk.session.user)):null;throw new Error(l)}throw new Error("Clerk: Child of WithClerk must be a function.")}))},exports.useClerk=function(){var e=r.useContext(c);if(e){if(e.guaranteedLoaded)return e.clerk;throw new Error("Clerk: You're calling useClerk() before there's a guarantee the client has been loaded. Call useClerk() from a child of <SignedIn>, <SignedOut>, or <ClerkLoaded>, or use the withClerk() HOC.")}throw new Error(l)},exports.useUser=function(){var e=r.useContext(c);if(e){if(e.guaranteedUser&&e.clerk.session)return e.clerk.session.user;throw new Error("Clerk: You're calling useUser() before there's a guarantee there's an active user. Call useUser() from a child of <SignedIn> or use the withUser() HOC.")}throw new Error(l)},exports.withClerk=d,exports.withUser=p; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("react"),n=(e=r)&&"object"==typeof e&&"default"in e?e.default:e;function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function o(e,r){e.prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r}function i(e,r){if(null==e)return{};var n,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)r.indexOf(n=i[t])>=0||(o[n]=e[n]);return o}function s(){return"undefined"!=typeof window}var l="Clerk: You must wrap your application in a <ClerkProvider> component.",u=function(){function e(e,r,n){var t=this,o=this;void 0===r&&(r={}),this.listeners=[],this.clerkjs=null,this.preopenSignIn=null,this.preopenSignUp=null,this.premountSignInNodes=new Map,this.premountSignUpNodes=new Map,this.premountUserProfileNodes=new Map,this.premountUserButtonNodes=new Map,this.premountMethodCalls=new Map,this._loaded=!1,this.ssrData=null,this.hydrateClerkJS=function(e){try{if(!e)throw new Error("Failed to hydrate latest Clerk JS");return o.clerkjs=e,o.listeners.forEach((function(r){e.addListener(r)})),null!==o.preopenSignIn&&e.openSignIn(o.preopenSignIn),null!==o.preopenSignUp&&e.openSignUp(o.preopenSignUp),o.premountSignInNodes.forEach((function(r,n){e.mountSignIn(n,r)})),o.premountSignUpNodes.forEach((function(r,n){e.mountSignUp(n,r)})),o.premountUserProfileNodes.forEach((function(r,n){e.mountUserProfile(n,r)})),o.premountUserButtonNodes.forEach((function(r,n){e.mountUserButton(n,r)})),o.premountMethodCalls.forEach((function(e){return e()})),o._loaded=!0,Promise.resolve(o.clerkjs)}catch(e){return Promise.reject(e)}},this.setSession=function(e,r){return t.clerkjs?t.clerkjs.setSession(e,r):Promise.reject()},this.openSignIn=function(e){t.clerkjs&&t._loaded?t.clerkjs.openSignIn(e):t.preopenSignIn=e},this.closeSignIn=function(){t.clerkjs&&t._loaded?t.clerkjs.closeSignIn():t.preopenSignIn=null},this.openSignUp=function(e){t.clerkjs&&t._loaded?t.clerkjs.openSignUp(e):t.preopenSignUp=e},this.closeSignUp=function(){t.clerkjs&&t._loaded?t.clerkjs.closeSignUp():t.preopenSignUp=null},this.mountSignIn=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountSignIn(e,r):t.premountSignInNodes.set(e,r)},this.unmountSignIn=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountSignIn(e):t.premountSignInNodes.delete(e)},this.mountSignUp=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountSignUp(e,r):t.premountSignUpNodes.set(e,r)},this.unmountSignUp=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountSignUp(e):t.premountSignUpNodes.delete(e)},this.mountUserProfile=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountUserProfile(e,r):t.premountUserProfileNodes.set(e,r)},this.unmountUserProfile=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountUserProfile(e):t.premountUserProfileNodes.delete(e)},this.mountUserButton=function(e,r){t.clerkjs&&t._loaded?t.clerkjs.mountUserButton(e,r):t.premountUserButtonNodes.set(e,r)},this.unmountUserButton=function(e){t.clerkjs&&t._loaded?t.clerkjs.unmountUserButton(e):t.premountUserButtonNodes.delete(e)},this.addListener=function(e){t.clerkjs?t.clerkjs.addListener(e):t.listeners.push(e)},this.loadFromServer=function(e){"browser"===t.mode&&t.throwError("loadFromServer cannot be called in a browser context."),t.ssrData=JSON.stringify({client:t.client,session:t.session,token:e})},this.navigate=function(e){var r=function(){var r;return null===(r=t.clerkjs)||void 0===r?void 0:r.navigate(e)};t.clerkjs&&t._loaded?r():t.premountMethodCalls.set("navigate",r)},this.redirectToSignIn=function(){var e=function(){var e;return null===(e=t.clerkjs)||void 0===e?void 0:e.redirectToSignIn()};t.clerkjs&&t._loaded?e():t.premountMethodCalls.set("redirectToSignIn",e)},this.redirectToSignUp=function(){var e=function(){var e;return null===(e=t.clerkjs)||void 0===e?void 0:e.redirectToSignUp()};t.clerkjs&&t._loaded?e():t.premountMethodCalls.set("redirectToSignUp",e)},this.redirectToUserProfile=function(){var e=function(){var e;return null===(e=t.clerkjs)||void 0===e?void 0:e.redirectToUserProfile()};t.clerkjs&&t._loaded?e():t.premountMethodCalls.set("redirectToUserProfile",e)},this.frontendApi=e,this.options=r,this.ClerkConstructor=n,this.mode=s()?"browser":"server"}var r,n=e.prototype;return n.loadClerkJS=function(){var e,r,n=this;return this.frontendApi?this.ClerkConstructor?(window.Clerk=new this.ClerkConstructor(this.frontendApi),window.Clerk.load(this.options).then((function(){return n.hydrateClerkJS(window.Clerk)})).catch((function(e){return n.throwError(e.message||e)}))):(e=this.frontendApi,r=this.options.scriptUrl,new Promise((function(n,t){window.Clerk&&n(null),e||t("Clerk: Missing provider");var o=document.createElement("script"),i=function(e,r){if(r)return r;var n=function(e){return e.endsWith(".lclstage.dev")||e.endsWith(".stgstage.dev")||e.endsWith(".clerkstage.dev")}(e)?"staging":parseInt("1.6.1-staging.0".split(".")[0],10);return"https://"+e+"/npm/@clerk/clerk-js@"+n+"/dist/clerk.browser.js"}(e,r);o.setAttribute("data-clerk-frontend-api",e),o.setAttribute("crossorigin","anonymous"),o.async=!0,document.body||t("Clerk: Missing <body> element."),o.addEventListener("load",(function(){return n(o)})),o.addEventListener("error",(function(){return t("Clerk: Failed to load Clerk")})),o.src=i,document.body.appendChild(o)}))).then((function(){if(window.Clerk)return window.Clerk.load(n.options);throw new Error("Failed to download latest Clerk JS")})).then((function(){return n.hydrateClerkJS(window.Clerk)})).catch((function(e){return n.throwError(e.message||e)})):(this.throwError("Clerk: You must add the frontendApi prop to your <ClerkProvider>"),Promise.resolve())},n.throwError=function(e){return console.error(e),Promise.resolve()},(r=[{key:"client",get:function(){return this.clerkjs?this.clerkjs.client:void 0}},{key:"session",get:function(){return this.clerkjs?this.clerkjs.session:void 0}},{key:"user",get:function(){return this.clerkjs?this.clerkjs.user:void 0}},{key:"environment",get:function(){return this.clerkjs?this.clerkjs.environment:void 0}}])&&function(e,r){for(var n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}(e.prototype,r),e}(),c=n.createContext(void 0);c.displayName="ClerkContext";var a=function(e){function r(r){var n;(n=e.call(this,r)||this).onClerkEvent=function(e){n.setState({client:e.client,session:e.session,user:e.user})};var t=r.frontendApi,o=void 0===t?"":t,s=r.Clerk,l=i(r,["frontendApi","Clerk"]);return n.clerk=new u(o,l,s),n.state={client:void 0,session:void 0,user:void 0},n}o(r,e);var t=r.prototype;return t.loadClerk=function(){var e=this;this.clerk.loadClerkJS().then((function(){e.setState({client:e.clerk.client,session:e.clerk.session,user:e.clerk.user})}))},t.componentDidMount=function(){this.loadClerk(),this.clerk&&this.clerk.addListener(this.onClerkEvent)},t.defaultInitialUser=function(e){var r=e.sessions.find((function(e){return"active"===e.status}));return r?r.user:null},t.render=function(){var e=this.state.session;return n.createElement(c.Provider,{value:{guaranteedLoaded:!1,guaranteedUser:!1,clerk:this.clerk}},this.clerk instanceof u&&this.clerk.ssrData&&n.createElement("script",{type:"application/json","data-clerk":"SSR",dangerouslySetInnerHTML:{__html:this.clerk.ssrData}}),n.createElement(n.Fragment,{key:e?e.id:"no-usrses"},this.props.children))},r}(n.PureComponent),d=function(e,o){e.displayName=o=o||e.displayName||e.name||"Component";var i=function(o){var i=r.useContext(c);if(i)return i.clerk&&void 0===i.clerk.session?null:i.guaranteedLoaded?n.createElement(e,Object.assign({},o,{clerk:i.clerk})):i.clerk.client?n.createElement(c.Provider,{value:t({},i,{guaranteedLoaded:!0})},n.createElement(e,Object.assign({},o,{clerk:i.clerk}))):null;if(s())throw new Error(l);return null};return i.displayName="withClerk("+o+")",i},p=function(e,o){e.displayName=o=o||e.displayName||e.name||"Component";var i=function(o){var i=r.useContext(c);if(i)return i.guaranteedUser&&i.clerk.session?n.createElement(e,Object.assign({},o,{user:i.clerk.session.user})):i.clerk.client&&i.clerk.session?n.createElement(c.Provider,{value:t({},i,{guaranteedLoaded:!0,guaranteedUser:!0})},n.createElement(e,Object.assign({},o,{user:i.clerk.session.user}))):null;if(s())throw new Error(l);return null};return i.displayName="withUser("+o+")",i},f=function(e){function r(){var r;return(r=e.apply(this,arguments)||this).portalRef=n.createRef(),r}o(r,e);var t=r.prototype;return t.componentDidMount=function(){this.portalRef.current&&this.props.mount(this.portalRef.current,this.props.props)},t.componentWillUnmount=function(){this.portalRef.current&&this.props.unmount(this.portalRef.current)},t.render=function(){return n.createElement("div",{ref:this.portalRef})},r}(n.PureComponent),k=d((function(e){var r=e.clerk,t=i(e,["clerk"]);return n.createElement(f,{mount:r.mountSignIn,unmount:r.unmountSignIn,props:t})}),"SignIn"),h=d((function(e){var r=e.clerk,t=i(e,["clerk"]);return n.createElement(f,{mount:r.mountSignUp,unmount:r.unmountSignUp,props:t})}),"SignUp"),m=d((function(e){var r=e.clerk,t=i(e,["clerk"]);return n.createElement(f,{mount:r.mountUserProfile,unmount:r.unmountUserProfile,props:t})}),"UserProfile"),g=d((function(e){var r=e.clerk,t=i(e,["clerk"]);return n.createElement(f,{mount:r.mountUserButton,unmount:r.unmountUserButton,props:t})}),"UserButton"),v=p((function(e){return n.createElement(n.Fragment,null,e.children)}),"SignedIn"),S=d((function(e){return null===e.clerk.session?n.createElement(n.Fragment,null,e.children):null}),"SignedOut"),C=d((function(e){return n.createElement(n.Fragment,null,e.children)}),"ClerkLoaded"),U=d((function(e){var r=e.clerk;return n.useEffect((function(){r.redirectToSignIn()}),[]),null}),"RedirectToSignIn"),w=d((function(e){var r=e.clerk;return n.useEffect((function(){r.redirectToSignUp()}),[]),null}),"RedirectToSignUp"),j=d((function(e){var r=e.clerk;return n.useEffect((function(){r.redirectToUserProfile()}),[]),null}),"redirectToUserProfile");exports.ClerkContext=c,exports.ClerkLoaded=C,exports.ClerkProvider=a,exports.RedirectToSignIn=U,exports.RedirectToSignUp=w,exports.RedirectToUserProfile=j,exports.SignIn=k,exports.SignUp=h,exports.SignedIn=v,exports.SignedOut=S,exports.UserButton=g,exports.UserProfile=m,exports.WithClerk=function(e){var r=e.children;return n.createElement(c.Consumer,null,(function(e){if("function"==typeof r){if(e)return e.clerk&&void 0===e.clerk.session?null:e.guaranteedLoaded?r(e.clerk):e.clerk.client?n.createElement(c.Provider,{value:t({},e,{guaranteedLoaded:!0})},r(e.clerk)):null;throw new Error(l)}throw new Error("Clerk: Child of WithClerk must be a function.")}))},exports.WithUser=function(e){var r=e.children;return n.createElement(c.Consumer,null,(function(e){if("function"==typeof r){if(e)return e.guaranteedUser&&e.clerk.session?r(e.clerk.session.user):e.clerk.client&&e.clerk.session?n.createElement(c.Provider,{value:t({},e,{guaranteedLoaded:!0,guaranteedUser:!0})},r(e.clerk.session.user)):null;throw new Error(l)}throw new Error("Clerk: Child of WithClerk must be a function.")}))},exports.useClerk=function(){var e=r.useContext(c);if(e){if(e.guaranteedLoaded)return e.clerk;throw new Error("Clerk: You're calling useClerk() before there's a guarantee the client has been loaded. Call useClerk() from a child of <SignedIn>, <SignedOut>, or <ClerkLoaded>, or use the withClerk() HOC.")}throw new Error(l)},exports.useUser=function(){var e=r.useContext(c);if(e){if(e.guaranteedUser&&e.clerk.session)return e.clerk.session.user;throw new Error("Clerk: You're calling useUser() before there's a guarantee there's an active user. Call useUser() from a child of <SignedIn> or use the withUser() HOC.")}throw new Error(l)},exports.withClerk=d,exports.withUser=p; | ||
//# sourceMappingURL=clerk-react.cjs.production.min.js.map |
@@ -62,3 +62,3 @@ import React, { useContext } from 'react'; | ||
var version = "1.6.0"; | ||
var version = "1.6.1-staging.0"; | ||
@@ -136,2 +136,3 @@ var FAILED_TO_LOAD_ERROR = 'Clerk: Failed to load Clerk'; | ||
this.premountUserButtonNodes = new Map(); | ||
this.premountMethodCalls = new Map(); | ||
this._loaded = false; | ||
@@ -176,2 +177,6 @@ this.ssrData = null; | ||
_this.premountMethodCalls.forEach(function (cb) { | ||
return cb(); | ||
}); | ||
_this._loaded = true; | ||
@@ -308,2 +313,58 @@ return Promise.resolve(_this.clerkjs); | ||
this.navigate = function (to) { | ||
var callback = function callback() { | ||
var _this2$clerkjs; | ||
return (_this2$clerkjs = _this2.clerkjs) === null || _this2$clerkjs === void 0 ? void 0 : _this2$clerkjs.navigate(to); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('navigate', callback); | ||
} | ||
}; | ||
this.redirectToSignIn = function () { | ||
var callback = function callback() { | ||
var _this2$clerkjs2; | ||
return (_this2$clerkjs2 = _this2.clerkjs) === null || _this2$clerkjs2 === void 0 ? void 0 : _this2$clerkjs2.redirectToSignIn(); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('redirectToSignIn', callback); | ||
} | ||
}; | ||
this.redirectToSignUp = function () { | ||
var callback = function callback() { | ||
var _this2$clerkjs3; | ||
return (_this2$clerkjs3 = _this2.clerkjs) === null || _this2$clerkjs3 === void 0 ? void 0 : _this2$clerkjs3.redirectToSignUp(); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('redirectToSignUp', callback); | ||
} | ||
}; | ||
this.redirectToUserProfile = function () { | ||
var callback = function callback() { | ||
var _this2$clerkjs4; | ||
return (_this2$clerkjs4 = _this2.clerkjs) === null || _this2$clerkjs4 === void 0 ? void 0 : _this2$clerkjs4.redirectToUserProfile(); | ||
}; | ||
if (_this2.clerkjs && _this2._loaded) { | ||
callback(); | ||
} else { | ||
_this2.premountMethodCalls.set('redirectToUserProfile', callback); | ||
} | ||
}; | ||
this.frontendApi = frontendApi; | ||
@@ -729,4 +790,25 @@ this.options = options; | ||
}, 'ClerkLoaded'); | ||
var RedirectToSignIn = /*#__PURE__*/withClerk(function (_ref11) { | ||
var clerk = _ref11.clerk; | ||
React.useEffect(function () { | ||
clerk.redirectToSignIn(); | ||
}, []); | ||
return null; | ||
}, 'RedirectToSignIn'); | ||
var RedirectToSignUp = /*#__PURE__*/withClerk(function (_ref12) { | ||
var clerk = _ref12.clerk; | ||
React.useEffect(function () { | ||
clerk.redirectToSignUp(); | ||
}, []); | ||
return null; | ||
}, 'RedirectToSignUp'); | ||
var RedirectToUserProfile = /*#__PURE__*/withClerk(function (_ref13) { | ||
var clerk = _ref13.clerk; | ||
React.useEffect(function () { | ||
clerk.redirectToUserProfile(); | ||
}, []); | ||
return null; | ||
}, 'redirectToUserProfile'); | ||
export { ClerkContext, ClerkLoaded, ClerkProvider, SignIn, SignUp, SignedIn, SignedOut, UserButton, UserProfile, WithClerk, WithUser, useClerk, useUser, withClerk, withUser }; | ||
export { ClerkContext, ClerkLoaded, ClerkProvider, RedirectToSignIn, RedirectToSignUp, RedirectToUserProfile, SignIn, SignUp, SignedIn, SignedOut, UserButton, UserProfile, WithClerk, WithUser, useClerk, useUser, withClerk, withUser }; | ||
//# sourceMappingURL=clerk-react.esm.js.map |
import React from 'react'; | ||
import { ClerkContextType, ClerkProviderProps, ClerkProviderState, ListenerEmission, LoadedClerk, SignInProps, SignUpProps, UserButtonProps, UserProfileProps, UserResource } from './types'; | ||
import { ClerkContextType, ClerkProviderProps, ClerkProviderState, ClientResource, ListenerEmission, LoadedClerk, SignInProps, SignUpProps, UserButtonProps, UserProfileProps, UserResource } from './types'; | ||
export * from './types'; | ||
export { ClerkContext, ClerkProvider, SignIn, SignUp, UserProfile, UserButton, useClerk, withClerk, WithClerk, useUser, withUser, WithUser, SignedIn, SignedOut, ClerkLoaded, }; | ||
export { ClerkContext, ClerkProvider, SignIn, SignUp, UserProfile, UserButton, useClerk, withClerk, WithClerk, useUser, withUser, WithUser, SignedIn, SignedOut, ClerkLoaded, RedirectToSignIn, RedirectToSignUp, RedirectToUserProfile, }; | ||
declare const ClerkContext: React.Context<ClerkContextType | undefined>; | ||
@@ -12,3 +12,3 @@ declare class ClerkProvider extends React.PureComponent<ClerkProviderProps, ClerkProviderState> { | ||
componentDidMount(): void; | ||
defaultInitialUser(client: any): any; | ||
defaultInitialUser(client: ClientResource): UserResource | null; | ||
render(): JSX.Element; | ||
@@ -37,1 +37,4 @@ } | ||
declare const ClerkLoaded: React.FC; | ||
declare const RedirectToSignIn: React.FC; | ||
declare const RedirectToSignUp: React.FC; | ||
declare const RedirectToUserProfile: React.FC; |
@@ -15,2 +15,3 @@ import type { BrowserClerk, BrowserClerkConstructor, ClerkOptions, ClientResource, ListenerEmission, SessionResource, SignInProps, SignUpProps, UserButtonProps, UserProfileProps } from './types'; | ||
private premountUserButtonNodes; | ||
private premountMethodCalls; | ||
private _loaded; | ||
@@ -43,2 +44,6 @@ ssrData: string | null; | ||
loadFromServer: (token: string) => void; | ||
navigate: (to: string | undefined) => void; | ||
redirectToSignIn: () => void; | ||
redirectToSignUp: () => void; | ||
redirectToUserProfile: () => void; | ||
} |
@@ -82,2 +82,6 @@ declare global { | ||
setSession: (session: SessionResource | string | null, beforeEmit?: (session: SessionResource | null) => any) => Promise<void>; | ||
navigate: (to: string | undefined) => void; | ||
redirectToSignIn: () => void; | ||
redirectToSignUp: () => void; | ||
redirectToUserProfile: () => void; | ||
} | ||
@@ -84,0 +88,0 @@ declare type RoutingStrategy = 'path' | 'hash' | 'virtual'; |
{ | ||
"name": "@clerk/clerk-react", | ||
"version": "1.6.0", | ||
"version": "1.6.1-staging.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Clerk.dev React library", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196945
1908
3