@enterprisestandard/react 0.0.3-beta.1 → 0.0.3-beta.2

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.
package/dist/index.js CHANGED
@@ -232,8 +232,9 @@ function sso(config) {
232
232
  }
233
233
  async function fetchJwks() {
234
234
  const url = configWithDefaults.jwks_uri || `${configWithDefaults.authority}/protocol/openid-connect/certs`;
235
- if (jwksCache.has(url))
236
- return jwksCache.get(url);
235
+ const cached = jwksCache.get(url);
236
+ if (cached)
237
+ return cached;
237
238
  return retryWithBackoff(async () => {
238
239
  if (!configWithDefaults)
239
240
  throw new Error("SSO Manager not initialized");
@@ -616,7 +617,7 @@ function SignInLoading({ complete = false, children }) {
616
617
  return /* @__PURE__ */ jsxDEV(Fragment, {
617
618
  children
618
619
  }, undefined, false, undefined, this);
619
- return /* @__PURE__ */ jsxDEV(Fragment, {}, undefined, false, undefined, this);
620
+ return null;
620
621
  }
621
622
  // src/ui/signed-in.tsx
622
623
  import { jsxDEV as jsxDEV2, Fragment as Fragment2 } from "react/jsx-dev-runtime";
@@ -626,14 +627,14 @@ function SignedIn({ children }) {
626
627
  return /* @__PURE__ */ jsxDEV2(Fragment2, {
627
628
  children
628
629
  }, undefined, false, undefined, this);
629
- return /* @__PURE__ */ jsxDEV2(Fragment2, {}, undefined, false, undefined, this);
630
+ return null;
630
631
  }
631
632
  // src/ui/signed-out.tsx
632
633
  import { jsxDEV as jsxDEV3, Fragment as Fragment3 } from "react/jsx-dev-runtime";
633
634
  function SignedOut({ children }) {
634
635
  const { user } = useUser();
635
636
  if (user)
636
- return /* @__PURE__ */ jsxDEV3(Fragment3, {}, undefined, false, undefined, this);
637
+ return null;
637
638
  return /* @__PURE__ */ jsxDEV3(Fragment3, {
638
639
  children
639
640
  }, undefined, false, undefined, this);
@@ -707,6 +708,12 @@ function SSOProvider({
707
708
  setIsLoading(true);
708
709
  try {
709
710
  const response = await fetch(userUrl);
711
+ if (response.status === 401) {
712
+ setUserState(null);
713
+ saveUserToStorage(null);
714
+ setIsLoading(false);
715
+ return;
716
+ }
710
717
  if (!response.ok) {
711
718
  throw new Error(`Failed to fetch user: ${response.status} ${response.statusText}`);
712
719
  }
@@ -728,8 +735,8 @@ function SSOProvider({
728
735
  const storedUser = loadUserFromStorage();
729
736
  if (storedUser) {
730
737
  setUserState(storedUser);
731
- setIsLoading(false);
732
- } else if (userUrl) {
738
+ }
739
+ if (userUrl) {
733
740
  fetchUserFromUrl();
734
741
  } else {
735
742
  setIsLoading(false);
@@ -799,6 +806,13 @@ function useToken() {
799
806
  setError(null);
800
807
  try {
801
808
  const response = await fetch(url);
809
+ if (response.status === 401) {
810
+ context.setUser(null);
811
+ setToken(null);
812
+ setExpires(null);
813
+ setIsLoading(false);
814
+ return;
815
+ }
802
816
  if (!response.ok) {
803
817
  throw new Error(`Failed to fetch JWT: ${response.status} ${response.statusText}`);
804
818
  }
@@ -814,7 +828,7 @@ function useToken() {
814
828
  } finally {
815
829
  setIsLoading(false);
816
830
  }
817
- }, []);
831
+ }, [context]);
818
832
  const refresh = useCallback(async () => {
819
833
  const url = refreshUrl || tokenUrl;
820
834
  if (!url) {
@@ -1,4 +1,4 @@
1
1
  import type { PropsWithChildren } from 'react';
2
2
  export declare function SignInLoading({ complete, children }: {
3
3
  complete?: boolean;
4
- } & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
4
+ } & PropsWithChildren): import("react/jsx-runtime").JSX.Element | null;
@@ -1,2 +1,2 @@
1
1
  import type { PropsWithChildren } from 'react';
2
- export declare function SignedIn({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
2
+ export declare function SignedIn({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element | null;
@@ -1,2 +1,2 @@
1
1
  import type { PropsWithChildren } from 'react';
2
- export declare function SignedOut({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
2
+ export declare function SignedOut({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enterprisestandard/react",
3
- "version": "0.0.3-beta.1",
3
+ "version": "0.0.3-beta.2",
4
4
  "description": "Enterprise Standard React Components",
5
5
  "private": false,
6
6
  "main": "dist/index.js",