import t from"netlify-identity-widget";var n=function(){function n(n){var e=this;this.dispatch=n.dispatch,this.netlifyIdentity=t,this.netlifyIdentity.init(n),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}}))})}n.addDefaultParams=function(t,n){return void 0===t&&(t={}),t};var e=n.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,n=function(n){var e,i=t.netlifyIdentity.currentUser();if(i)return{user:i,authResult:{expiresIn:null==(e=i.token)?void 0:e.expires_in}};throw new Error("Session invalid")},e=function(n,e){try{var i=Promise.resolve(t.netlifyIdentity.refresh()).then(function(){})}catch(t){return e()}return i&&i.then?i.then(void 0,e):i}(0,function(){throw new Error("Session invalid")});return Promise.resolve(e&&e.then?e.then(n):n())}catch(t){return Promise.reject(t)}},e.userId=function(t){return t.id},e.userRoles=function(t){return t.app_metadata.roles},n}();export{n as NetlifyIdentity};
//# sourceMappingURL=NetlifyIdentity.esm.js.map
