umwd-components 0.1.666 → 0.1.667

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__read as e,__awaiter as r,__generator as n}from"../../../node_modules/tslib/tslib.es6.js";import t,{useState as o,useEffect as s,useContext as i,createContext as u}from"react";import{getAuthToken as c}from"../../data/services/get-token.js";import{getUserMeLoader as a}from"../../data/services/get-user-me-loader.js";import{loginUserService as l}from"../../data/services/auth-service.js";import{logoutAction as d}from"../../data/actions/auth-actions.js";import{useSearchParams as f}from"next/navigation";import{useCookieConsent as v}from"../../components/common/cookie-consent/CookieConsentContext.js";var h=u(void 0),m=function(i){var u=i.children,m=e(o(null),2),g=m[0],p=m[1],w=e(o(!0),2),b=w[0],j=w[1],k=e(o(null),2),x=k[0],y=k[1],A=f(),C=v().consentGiven,E=function(){return r(void 0,void 0,void 0,(function(){var e,r;return n(this,(function(n){switch(n.label){case 0:j(!0),n.label=1;case 1:return n.trys.push([1,4,5,6]),[4,c()];case 2:return(e=n.sent())?[4,a(e)]:(j(!1),[2]);case 3:return(r=n.sent())?p(r):y("Failed to fetch user details"),[3,6];case 4:return n.sent(),y("An error occurred while fetching user details"),[3,6];case 5:return j(!1),[7];case 6:return[2]}}))}))};s((function(){E()}),[]),s((function(){var e=setInterval((function(){return r(void 0,void 0,void 0,(function(){var e,r;return n(this,(function(n){switch(n.label){case 0:return[4,c()];case 1:return(e=n.sent())?[4,a(e)]:(p(null),[2]);case 2:return(r=n.sent())!==g&&p(r),[2]}}))}))}),3e3);return function(){return clearInterval(e)}}),[]),s((function(){A&&"success"===A.get("login")&&F()}),[A]);var S=function(){return r(void 0,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,d()];case 1:return e.sent(),p(null),[3,3];case 2:return e.sent(),y("An error occurred during logout"),[3,3];case 3:return[2]}}))}))},F=function(){return r(void 0,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,E()];case 1:return e.sent(),[3,3];case 2:return e.sent(),y("An error occurred while refreshing session"),[3,3];case 3:return[2]}}))}))};return s((function(){!1===C&&S()}),[C]),t.createElement(h.Provider,{value:{user:g,loading:b,error:x,login:function(e,t){return r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:j(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,l({identifier:e,password:t})];case 2:return(r=n.sent())&&r.jwt?(document.cookie="jwt=".concat(r.jwt,";path=/;max-age=604800;secure"),p(r.user)):y("Failed to login"),[3,5];case 3:return n.sent(),y("An error occurred during login"),[3,5];case 4:return j(!1),[7];case 5:return[2]}}))}))},logout:S,refreshSession:F,clearError:function(){y(null)}}},u)},g=function(){var e=i(h);if(!e)throw new Error("useSession must be used within a SessionProvider");return e};export{m as SessionProvider,g as useSession};
7
+ import{__read as r,__awaiter as e,__generator as n}from"../../../node_modules/tslib/tslib.es6.js";import t,{useState as o,useEffect as s,useContext as i,createContext as u}from"react";import{getAuthToken as c}from"../../data/services/get-token.js";import{getUserMeLoader as a}from"../../data/services/get-user-me-loader.js";import{loginUserService as l}from"../../data/services/auth-service.js";import{logoutAction as d}from"../../data/actions/auth-actions.js";import{useSearchParams as v}from"next/navigation";import{useCookieConsent as f}from"../../components/common/cookie-consent/CookieConsentContext.js";var h=u(void 0),m=function(i){var u,m=i.children,g=r(o(null),2),p=g[0],w=g[1],b=r(o(!0),2),j=b[0],y=b[1],k=r(o(null),2),x=k[0],A=k[1],C=v(),E=!0;try{var S=f();E=null===(u=null==S?void 0:S.consentGiven)||void 0===u||u}catch(r){E=!0}var F=function(){return e(void 0,void 0,void 0,(function(){var r,e;return n(this,(function(n){switch(n.label){case 0:y(!0),n.label=1;case 1:return n.trys.push([1,4,5,6]),[4,c()];case 2:return(r=n.sent())?[4,a(r)]:(y(!1),[2]);case 3:return(e=n.sent())?w(e):A("Failed to fetch user details"),[3,6];case 4:return n.sent(),A("An error occurred while fetching user details"),[3,6];case 5:return y(!1),[7];case 6:return[2]}}))}))};s((function(){F()}),[]),s((function(){var r=setInterval((function(){return e(void 0,void 0,void 0,(function(){var r,e;return n(this,(function(n){switch(n.label){case 0:return[4,c()];case 1:return(r=n.sent())?[4,a(r)]:(w(null),[2]);case 2:return(e=n.sent())!==p&&w(e),[2]}}))}))}),3e3);return function(){return clearInterval(r)}}),[]),s((function(){C&&"success"===C.get("login")&&P()}),[C]);var I=function(){return e(void 0,void 0,void 0,(function(){return n(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,d()];case 1:return r.sent(),w(null),[3,3];case 2:return r.sent(),A("An error occurred during logout"),[3,3];case 3:return[2]}}))}))},P=function(){return e(void 0,void 0,void 0,(function(){return n(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,F()];case 1:return r.sent(),[3,3];case 2:return r.sent(),A("An error occurred while refreshing session"),[3,3];case 3:return[2]}}))}))};return s((function(){!1===E&&I()}),[E]),t.createElement(h.Provider,{value:{user:p,loading:j,error:x,login:function(r,t){return e(void 0,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:y(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,l({identifier:r,password:t})];case 2:return(e=n.sent())&&e.jwt?(document.cookie="jwt=".concat(e.jwt,";path=/;max-age=604800;secure"),w(e.user)):A("Failed to login"),[3,5];case 3:return n.sent(),A("An error occurred during login"),[3,5];case 4:return y(!1),[7];case 5:return[2]}}))}))},logout:I,refreshSession:P,clearError:function(){A(null)}}},m)},g=function(){var r=i(h);if(!r)throw new Error("useSession must be used within a SessionProvider");return r};export{m as SessionProvider,g as useSession};