var e=require("auth0-js");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}exports.Auth0=function(){function n(r){this.dispatch=r.dispatch,this.customPropertyNamespace=r.customPropertyNamespace,this.auth0=new e.WebAuth(t({},r))}n.addDefaultParams=function(e,r){return t({redirectUri:r+"/auth0_callback",audience:"https://"+e.domain+"/api/v2/",responseType:"token id_token",scope:"openid profile email"},e)};var o=n.prototype;return o.authorize=function(){this.auth0.authorize()},o.signup=function(){this.auth0.authorize({mode:"signUp",screen_hint:"signup"})},o.logout=function(e){this.auth0.logout({returnTo:e})},o.userId=function(e){return e.sub},o.userRoles=function(e){var t=e[(this.customPropertyNamespace+"/user_metadata").replace(/\/+user_metadata/,"/user_metadata")];return(null==t?void 0:t.roles)||null},o.handleLoginCallback=function(){try{var e=this;return Promise.resolve(new Promise(function(t,n){e.auth0.parseHash(function(n,o){try{n&&(e.dispatch("ERROR",{error:n,errorType:"authResult"}),t(!1));var u=r(function(){return Promise.resolve(e.handleAuthResult(o)).then(function(e){t(e)})},function(r){e.dispatch("ERROR",{error:r,errorType:"handleAuth"}),t(!1)});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},o.checkSession=function(){try{var e=this;return Promise.resolve(new Promise(function(t,n){e.auth0.checkSession({},function(o,u){try{var i=function(){if(!o&&u&&u.accessToken&&u.idToken){var i=r(function(){return Promise.resolve(e.fetchUser(u)).then(function(e){t({user:e,authResult:u})})},function(e){n(e)});if(i&&i.then)return i.then(function(){})}else n(o||new Error("Session invalid"))}();return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},o.handleAuthResult=function(e){try{var t=this;return e&&e.accessToken&&e.idToken?Promise.resolve(t.fetchUser(e)).then(function(r){return t.dispatch("AUTHENTICATED",{authResult:e,user:r}),!0}):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},o.fetchUser=function(e){try{var t=this;return Promise.resolve(new Promise(function(r,n){t.auth0.client.userInfo((null==e?void 0:e.accessToken)||"",function(e,t){e?n(e):r(t)})}))}catch(e){return Promise.reject(e)}},n}();
//# sourceMappingURL=auth0.js.map
