!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("netlify-identity-widget")):"function"==typeof define&&define.amd?define(["exports","netlify-identity-widget"],e):e((t||self).reactUseAuth={},t.netlifyIdentityWidget)}(this,function(t,e){function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=n(e);t.NetlifyIdentity=function(){function t(t){var e=this;this.dispatch=t.dispatch,this.netlifyIdentity=i.default,this.netlifyIdentity.init(t),this.netlifyIdentity.on("error",function(t){e.dispatch("ERROR",{error:t,errorType:"netlifyError"})}),this.netlifyIdentity.on("login",function(t){var n;e.dispatch("AUTHENTICATED",{user:t,authResult:{expiresIn:null==(n=t.token)?void 0:n.expires_in}})}),this.netlifyIdentity.on("init",function(t){var n;t&&(e.dispatch("LOGIN"),e.dispatch("AUTHENTICATED",{user:t,authResult:{expiresIn:null==(n=t.token)?void 0:n.expires_in}}))})}t.addDefaultParams=function(t,e){return void 0===t&&(t={}),t};var e=t.prototype;return e.authorize=function(){this.dispatch("LOGIN"),this.netlifyIdentity.open("login")},e.signup=function(){this.dispatch("LOGIN"),this.netlifyIdentity.open("signup")},e.logout=function(t){this.netlifyIdentity.logout()},e.handleLoginCallback=function(t){try{return console.warn("handleLoginCallback is unnecessary with Netlify Identity Widget"),Promise.resolve(!0)}catch(t){return Promise.reject(t)}},e.checkSession=function(){try{var t=this,e=function(e){var n,i=t.netlifyIdentity.currentUser();if(i)return{user:i,authResult:{expiresIn:null==(n=i.token)?void 0:n.expires_in}};throw new Error("Session invalid")},n=function(e,n){try{var i=Promise.resolve(t.netlifyIdentity.refresh()).then(function(){})}catch(t){return n()}return i&&i.then?i.then(void 0,n):i}(0,function(){throw new Error("Session invalid")});return Promise.resolve(n&&n.then?n.then(e):e())}catch(t){return Promise.reject(t)}},e.userId=function(t){return t.id},e.userRoles=function(t){return t.app_metadata.roles},t}()});
//# sourceMappingURL=NetlifyIdentity.umd.js.map
