@equinor/amplify-component-lib 8.4.4 → 8.4.5

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.
@@ -1 +1 @@
1
- import{jsx as o,Fragment as e}from"react/jsx-runtime";import{useState as r,useRef as t,useEffect as n}from"react";import{InteractionType as i,InteractionRequiredAuthError as c}from"@azure/msal-browser";import{useMsal as a,useMsalAuthentication as s}from"@azure/msal-react";import{auth as l,environment as u}from"../../atoms/utils/auth_environment.js";import{FullPageSpinner as d}from"../../molecules/FullPageSpinner/FullPageSpinner.js";import{Unauthorized as h}from"../../organisms/ErrorPage/collections/Unauthorized.js";import{jwtDecode as g}from"jwt-decode";const{GRAPH_ENDPOINTS:m,GRAPH_REQUESTS_LOGIN:A,GRAPH_REQUESTS_PHOTO:P,GRAPH_REQUESTS_BACKEND:v,fetchMsGraph:f,isInIframe:p}=l,{getApiScope:w}=u,S=({children:l,account:u,setAccount:S,setPhoto:E,setRoles:T,authState:R,setAuthState:z,loadingComponent:k,unauthorizedComponent:_})=>{const{instance:y,accounts:O,inProgress:U}=a(),{login:I,result:j,error:F,acquireToken:G}=s(i.Silent,A),[H,b]=r(!1),C=t(!1);return n((()=>{if(H)return;(async()=>{console.log("[AuthProvider] Initializing"),await y.initialize(),console.log("[AuthProvider] Finished initializing"),b(!0)})().catch((o=>{console.error("[AuthProvider] Error during initialization",o)}))}),[y,H]),n((()=>{H&&(F instanceof c&&!p()?(console.error(F),console.log("[AuthProvider] No account found, need to login via. redirect"),I(i.Redirect,A).catch((o=>{console.error("[AuthProvider] Error during login",o)}))):j?.account&&!u?(console.log("[AuthProvider] Found account in useMsalAuth result, setting that one as active"),y.setActiveAccount(j.account),S(j.account)):O.length>0&&!u?(console.log("[AuthProvider] Found account in accounts array, setting that one as active"),y.setActiveAccount(O[0]),S(O[0])):F&&console.error("[AuthProvider] Unexpected error:",F))}),[u,O,F,y,H,I,j,S]),n((()=>{if(!u||!H||C.current||"none"!==U)return;C.current=!0;(async()=>{await(async()=>{try{const o=await G(i.Silent,P);if(o){const e=await f(m.PHOTO,o.accessToken);if(404===e.status)return null;const r=await e.blob(),t=(window.URL??window.webkitURL).createObjectURL(r);E(t)}}catch(o){console.error(o)}})(),await(async()=>{try{const o=await G(i.Silent,v(w(import.meta.env.VITE_API_SCOPE)));if(console.log("[AuthProvider] Successfully acquired token"),o&&o.accessToken){console.log("[AuthProvider] Decoding token");const e=g(o.accessToken);if(console.log("[AuthProvider] Token was valid"),!e.roles)throw new Error("Could not find roles in token");console.log("[AuthProvider] Found roles"),T(e.roles),z("authorized")}}catch(o){console.error("[AuthProvider] Token error when trying to get roles!",o),z("unauthorized")}})()})()}),[u,G,F,H,U,z,E,T]),"loading"===R||void 0===u?k??o(d,{variant:"application"}):"unauthorized"===R?_??o(h,{}):o(e,{children:l})};export{S as AuthProviderInner};
1
+ import{jsx as o,Fragment as e}from"react/jsx-runtime";import{useState as r,useRef as t,useEffect as n}from"react";import{InteractionType as i,InteractionRequiredAuthError as c}from"@azure/msal-browser";import{useMsal as a,useMsalAuthentication as s}from"@azure/msal-react";import{auth as u,environment as l}from"../../atoms/utils/auth_environment.js";import{FullPageSpinner as d}from"../../molecules/FullPageSpinner/FullPageSpinner.js";import{Unauthorized as h}from"../../organisms/ErrorPage/collections/Unauthorized.js";import{jwtDecode as g}from"jwt-decode";const{GRAPH_ENDPOINTS:m,GRAPH_REQUESTS_LOGIN:A,GRAPH_REQUESTS_PHOTO:P,GRAPH_REQUESTS_BACKEND:v,fetchMsGraph:f,isInIframe:p}=u,{getApiScope:w}=l,S=({children:u,account:l,setAccount:S,setPhoto:E,setRoles:T,authState:z,setAuthState:R,loadingComponent:k,unauthorizedComponent:_})=>{const{instance:y,accounts:O,inProgress:U}=a(),{login:I,result:j,error:F,acquireToken:G}=s(i.Silent,A),[H,b]=r(!1),C=t(!1);return n((()=>{if(H)return;(async()=>{console.log("[AuthProvider] Initializing"),await y.initialize(),console.log("[AuthProvider] Finished initializing"),b(!0)})().catch((o=>{console.error("[AuthProvider] Error during initialization",o)}))}),[y,H]),n((()=>{H&&(F instanceof c&&!p()&&"unauthorized"!==z?(console.error(F),console.log("[AuthProvider] No account found, need to login via. redirect"),I(i.Redirect,A).catch((o=>{console.error("[AuthProvider] Error during login",o)}))):j?.account&&!l?(console.log("[AuthProvider] Found account in useMsalAuth result, setting that one as active"),y.setActiveAccount(j.account),S(j.account)):O.length>0&&!l?(console.log("[AuthProvider] Found account in accounts array, setting that one as active"),y.setActiveAccount(O[0]),S(O[0])):F&&console.error("[AuthProvider] Unexpected error:",F))}),[l,O,F,y,H,I,j,S,z]),n((()=>{if(!l||!H||C.current||"none"!==U)return;C.current=!0;(async()=>{await(async()=>{try{const o=await G(i.Silent,P);if(o){const e=await f(m.PHOTO,o.accessToken);if(404===e.status)return null;const r=await e.blob(),t=(window.URL??window.webkitURL).createObjectURL(r);E(t)}}catch(o){console.error(o)}})(),await(async()=>{try{const o=await G(i.Silent,v(w(import.meta.env.VITE_API_SCOPE)));if(console.log("[AuthProvider] Successfully acquired token"),o&&o.accessToken){console.log("[AuthProvider] Decoding token");const e=g(o.accessToken);if(console.log("[AuthProvider] Token was valid"),!e.roles)throw new Error("Could not find roles in token");console.log("[AuthProvider] Found roles"),T(e.roles),R("authorized")}}catch(o){console.error("[AuthProvider] Token error when trying to get roles!",o),R("unauthorized")}})()})()}),[l,G,F,H,U,R,E,T]),"loading"===z||void 0===l?k??o(d,{variant:"application"}):"unauthorized"===z?_??o(h,{}):o(e,{children:u})};export{S as AuthProviderInner};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/amplify-component-lib",
3
- "version": "8.4.4",
3
+ "version": "8.4.5",
4
4
  "description": "Frontend Typescript components for the Amplify team",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",