@usehercules/auth 1.0.27 → 1.0.29

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,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var p=(t,e)=>{for(var o in e)u(t,o,{get:e[o],enumerable:!0})},v=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of f(e))!m.call(t,r)&&r!==o&&u(t,r,{get:()=>e[r],enumerable:!(n=d(e,r))||n.enumerable});return t};var A=t=>v(u({},"__esModule",{value:!0}),t);var x={};p(x,{ConvexProviderWithHerculesAuth:()=>C});module.exports=A(x);var s=require("convex/react"),i=require("react"),l=require("react-oidc-context"),h=require("react/jsx-runtime");function C({children:t,client:e}){return(0,h.jsx)(s.ConvexProviderWithAuth,{client:e,useAuth:k,children:t})}function k(){let{isAuthenticated:t,user:e,isLoading:o,signinSilent:n}=(0,l.useAuth)(),r=e?.id_token,c=(0,i.useCallback)(async({forceRefreshToken:a})=>{try{return a?(await n())?.id_token??null:r??null}catch{return null}},[r,n]);return(0,i.useMemo)(()=>({isLoading:o,isAuthenticated:t,fetchAccessToken:c}),[o,t,c])}0&&(module.exports={ConvexProviderWithHerculesAuth});
1
+ "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var o in e)c(t,o,{get:e[o],enumerable:!0})},p=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of a(e))!d.call(t,r)&&r!==o&&c(t,r,{get:()=>e[r],enumerable:!(n=f(e,r))||n.enumerable});return t};var v=t=>p(c({},"__esModule",{value:!0}),t);var k={};m(k,{ConvexProviderWithHerculesAuth:()=>A});module.exports=v(k);var s=require("convex/react"),i=require("react"),l=require("react-oidc-context"),h=require("react/jsx-runtime");function A({children:t,client:e}){return(0,h.jsx)(s.ConvexProviderWithAuth,{client:e,useAuth:C,children:t})}function C(){let{isAuthenticated:t,user:e,isLoading:o,signinSilent:n}=(0,l.useAuth)(),r=e?.id_token,u=(0,i.useCallback)(async({forceRefreshToken:x})=>{try{return r??null}catch{return null}},[r,n]);return(0,i.useMemo)(()=>({isLoading:o,isAuthenticated:t,fetchAccessToken:u}),[o,t,u])}0&&(module.exports={ConvexProviderWithHerculesAuth});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/convex-react/index.ts","../../src/convex-react/ConvexProviderWithHercules.tsx"],"sourcesContent":["export * from \"./ConvexProviderWithHercules\";\n","\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { ConvexProviderWithAuth, type ConvexReactClient } from \"convex/react\";\nimport { useCallback, useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\nimport type { HerculesAuthProvider } from \"../react/HerculesAuthProvider\";\n\n/**\n * A wrapper React component which provides a {@link ConvexReactClient}\n * authenticated with Hercules Auth.\n *\n * It must be wrapped by a configured `{@link HerculesAuthProvider}`.\n *\n * @public\n */\nexport function ConvexProviderWithHerculesAuth({\n children,\n client,\n}: {\n children: ReactNode;\n client: ConvexReactClient;\n}) {\n return (\n <ConvexProviderWithAuth client={client} useAuth={useUseAuthFromHercules}>\n {children}\n </ConvexProviderWithAuth>\n );\n}\n\nfunction useUseAuthFromHercules() {\n const { isAuthenticated, user, isLoading, signinSilent } = useAuth();\n const idToken = user?.id_token;\n const fetchAccessToken = useCallback(\n async ({ forceRefreshToken }: { forceRefreshToken: boolean }) => {\n try {\n if (forceRefreshToken) {\n const user = await signinSilent();\n return user?.id_token ?? null;\n }\n return idToken ?? null;\n } catch {\n return null;\n }\n },\n [idToken, signinSilent],\n );\n return useMemo(\n () => ({\n isLoading,\n isAuthenticated,\n fetchAccessToken,\n }),\n [isLoading, isAuthenticated, fetchAccessToken],\n );\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oCAAAE,IAAA,eAAAC,EAAAH,GCGA,IAAAI,EAA+D,wBAC/DA,EAAqC,iBACrCC,EAAwB,8BAmBpBC,EAAA,6BARG,SAASC,EAA+B,CAC7C,SAAAC,EACA,OAAAC,CACF,EAGG,CACD,SACE,OAAC,0BAAuB,OAAQA,EAAQ,QAASC,EAC9C,SAAAF,EACH,CAEJ,CAEA,SAASE,GAAyB,CAChC,GAAM,CAAE,gBAAAC,EAAiB,KAAAC,EAAM,UAAAC,EAAW,aAAAC,CAAa,KAAI,WAAQ,EAC7DC,EAAUH,GAAM,SAChBI,KAAmB,eACvB,MAAO,CAAE,kBAAAC,CAAkB,IAAsC,CAC/D,GAAI,CACF,OAAIA,GACW,MAAMH,EAAa,IACnB,UAAY,KAEpBC,GAAW,IACpB,MAAQ,CACN,OAAO,IACT,CACF,EACA,CAACA,EAASD,CAAY,CACxB,EACA,SAAO,WACL,KAAO,CACL,UAAAD,EACA,gBAAAF,EACA,iBAAAK,CACF,GACA,CAACH,EAAWF,EAAiBK,CAAgB,CAC/C,CACF","names":["convex_react_exports","__export","ConvexProviderWithHerculesAuth","__toCommonJS","import_react","import_react_oidc_context","import_jsx_runtime","ConvexProviderWithHerculesAuth","children","client","useUseAuthFromHercules","isAuthenticated","user","isLoading","signinSilent","idToken","fetchAccessToken","forceRefreshToken"]}
1
+ {"version":3,"sources":["../../src/convex-react/index.ts","../../src/convex-react/ConvexProviderWithHercules.tsx"],"sourcesContent":["export * from \"./ConvexProviderWithHercules\";\n","\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { ConvexProviderWithAuth, type ConvexReactClient } from \"convex/react\";\nimport { useCallback, useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\nimport type { HerculesAuthProvider } from \"../react/HerculesAuthProvider\";\n\n/**\n * A wrapper React component which provides a {@link ConvexReactClient}\n * authenticated with Hercules Auth.\n *\n * It must be wrapped by a configured `{@link HerculesAuthProvider}`.\n *\n * @public\n */\nexport function ConvexProviderWithHerculesAuth({\n children,\n client,\n}: {\n children: ReactNode;\n client: ConvexReactClient;\n}) {\n return (\n <ConvexProviderWithAuth client={client} useAuth={useUseAuthFromHercules}>\n {children}\n </ConvexProviderWithAuth>\n );\n}\n\nfunction useUseAuthFromHercules() {\n const { isAuthenticated, user, isLoading, signinSilent } = useAuth();\n const idToken = user?.id_token;\n const fetchAccessToken = useCallback(\n async ({ forceRefreshToken: _ignore }: { forceRefreshToken: boolean }) => {\n try {\n // if (forceRefreshToken) {\n // const user = await signinSilent();\n // return user?.id_token ?? null;\n // }\n return idToken ?? null;\n } catch {\n return null;\n }\n },\n [idToken, signinSilent],\n );\n return useMemo(\n () => ({\n isLoading,\n isAuthenticated,\n fetchAccessToken,\n }),\n [isLoading, isAuthenticated, fetchAccessToken],\n );\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oCAAAE,IAAA,eAAAC,EAAAH,GCGA,IAAAI,EAA+D,wBAC/DA,EAAqC,iBACrCC,EAAwB,8BAmBpBC,EAAA,6BARG,SAASC,EAA+B,CAC7C,SAAAC,EACA,OAAAC,CACF,EAGG,CACD,SACE,OAAC,0BAAuB,OAAQA,EAAQ,QAASC,EAC9C,SAAAF,EACH,CAEJ,CAEA,SAASE,GAAyB,CAChC,GAAM,CAAE,gBAAAC,EAAiB,KAAAC,EAAM,UAAAC,EAAW,aAAAC,CAAa,KAAI,WAAQ,EAC7DC,EAAUH,GAAM,SAChBI,KAAmB,eACvB,MAAO,CAAE,kBAAmBC,CAAQ,IAAsC,CACxE,GAAI,CAKF,OAAOF,GAAW,IACpB,MAAQ,CACN,OAAO,IACT,CACF,EACA,CAACA,EAASD,CAAY,CACxB,EACA,SAAO,WACL,KAAO,CACL,UAAAD,EACA,gBAAAF,EACA,iBAAAK,CACF,GACA,CAACH,EAAWF,EAAiBK,CAAgB,CAC/C,CACF","names":["convex_react_exports","__export","ConvexProviderWithHerculesAuth","__toCommonJS","import_react","import_react_oidc_context","import_jsx_runtime","ConvexProviderWithHerculesAuth","children","client","useUseAuthFromHercules","isAuthenticated","user","isLoading","signinSilent","idToken","fetchAccessToken","_ignore"]}
@@ -1,2 +1,2 @@
1
- import{ConvexProviderWithAuth as c}from"convex/react";import{useCallback as s,useMemo as l}from"react";import{useAuth as h}from"react-oidc-context";import{jsx as d}from"react/jsx-runtime";function A({children:e,client:t}){return d(c,{client:t,useAuth:a,children:e})}function a(){let{isAuthenticated:e,user:t,isLoading:r,signinSilent:o}=h(),n=t?.id_token,i=s(async({forceRefreshToken:u})=>{try{return u?(await o())?.id_token??null:n??null}catch{return null}},[n,o]);return l(()=>({isLoading:r,isAuthenticated:e,fetchAccessToken:i}),[r,e,i])}export{A as ConvexProviderWithHerculesAuth};
1
+ import{ConvexProviderWithAuth as c}from"convex/react";import{useCallback as u,useMemo as s}from"react";import{useAuth as l}from"react-oidc-context";import{jsx as f}from"react/jsx-runtime";function v({children:e,client:t}){return f(c,{client:t,useAuth:h,children:e})}function h(){let{isAuthenticated:e,user:t,isLoading:r,signinSilent:i}=l(),o=t?.id_token,n=u(async({forceRefreshToken:a})=>{try{return o??null}catch{return null}},[o,i]);return s(()=>({isLoading:r,isAuthenticated:e,fetchAccessToken:n}),[r,e,n])}export{v as ConvexProviderWithHerculesAuth};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/convex-react/ConvexProviderWithHercules.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { ConvexProviderWithAuth, type ConvexReactClient } from \"convex/react\";\nimport { useCallback, useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\nimport type { HerculesAuthProvider } from \"../react/HerculesAuthProvider\";\n\n/**\n * A wrapper React component which provides a {@link ConvexReactClient}\n * authenticated with Hercules Auth.\n *\n * It must be wrapped by a configured `{@link HerculesAuthProvider}`.\n *\n * @public\n */\nexport function ConvexProviderWithHerculesAuth({\n children,\n client,\n}: {\n children: ReactNode;\n client: ConvexReactClient;\n}) {\n return (\n <ConvexProviderWithAuth client={client} useAuth={useUseAuthFromHercules}>\n {children}\n </ConvexProviderWithAuth>\n );\n}\n\nfunction useUseAuthFromHercules() {\n const { isAuthenticated, user, isLoading, signinSilent } = useAuth();\n const idToken = user?.id_token;\n const fetchAccessToken = useCallback(\n async ({ forceRefreshToken }: { forceRefreshToken: boolean }) => {\n try {\n if (forceRefreshToken) {\n const user = await signinSilent();\n return user?.id_token ?? null;\n }\n return idToken ?? null;\n } catch {\n return null;\n }\n },\n [idToken, signinSilent],\n );\n return useMemo(\n () => ({\n isLoading,\n isAuthenticated,\n fetchAccessToken,\n }),\n [isLoading, isAuthenticated, fetchAccessToken],\n );\n}\n"],"mappings":"AAGA,OAAS,0BAAAA,MAAsD,eAC/D,OAAS,eAAAC,EAAa,WAAAC,MAAe,QACrC,OAAS,WAAAC,MAAe,qBAmBpB,cAAAC,MAAA,oBARG,SAASC,EAA+B,CAC7C,SAAAC,EACA,OAAAC,CACF,EAGG,CACD,OACEH,EAACJ,EAAA,CAAuB,OAAQO,EAAQ,QAASC,EAC9C,SAAAF,EACH,CAEJ,CAEA,SAASE,GAAyB,CAChC,GAAM,CAAE,gBAAAC,EAAiB,KAAAC,EAAM,UAAAC,EAAW,aAAAC,CAAa,EAAIT,EAAQ,EAC7DU,EAAUH,GAAM,SAChBI,EAAmBb,EACvB,MAAO,CAAE,kBAAAc,CAAkB,IAAsC,CAC/D,GAAI,CACF,OAAIA,GACW,MAAMH,EAAa,IACnB,UAAY,KAEpBC,GAAW,IACpB,MAAQ,CACN,OAAO,IACT,CACF,EACA,CAACA,EAASD,CAAY,CACxB,EACA,OAAOV,EACL,KAAO,CACL,UAAAS,EACA,gBAAAF,EACA,iBAAAK,CACF,GACA,CAACH,EAAWF,EAAiBK,CAAgB,CAC/C,CACF","names":["ConvexProviderWithAuth","useCallback","useMemo","useAuth","jsx","ConvexProviderWithHerculesAuth","children","client","useUseAuthFromHercules","isAuthenticated","user","isLoading","signinSilent","idToken","fetchAccessToken","forceRefreshToken"]}
1
+ {"version":3,"sources":["../../src/convex-react/ConvexProviderWithHercules.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { ConvexProviderWithAuth, type ConvexReactClient } from \"convex/react\";\nimport { useCallback, useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\nimport type { HerculesAuthProvider } from \"../react/HerculesAuthProvider\";\n\n/**\n * A wrapper React component which provides a {@link ConvexReactClient}\n * authenticated with Hercules Auth.\n *\n * It must be wrapped by a configured `{@link HerculesAuthProvider}`.\n *\n * @public\n */\nexport function ConvexProviderWithHerculesAuth({\n children,\n client,\n}: {\n children: ReactNode;\n client: ConvexReactClient;\n}) {\n return (\n <ConvexProviderWithAuth client={client} useAuth={useUseAuthFromHercules}>\n {children}\n </ConvexProviderWithAuth>\n );\n}\n\nfunction useUseAuthFromHercules() {\n const { isAuthenticated, user, isLoading, signinSilent } = useAuth();\n const idToken = user?.id_token;\n const fetchAccessToken = useCallback(\n async ({ forceRefreshToken: _ignore }: { forceRefreshToken: boolean }) => {\n try {\n // if (forceRefreshToken) {\n // const user = await signinSilent();\n // return user?.id_token ?? null;\n // }\n return idToken ?? null;\n } catch {\n return null;\n }\n },\n [idToken, signinSilent],\n );\n return useMemo(\n () => ({\n isLoading,\n isAuthenticated,\n fetchAccessToken,\n }),\n [isLoading, isAuthenticated, fetchAccessToken],\n );\n}\n"],"mappings":"AAGA,OAAS,0BAAAA,MAAsD,eAC/D,OAAS,eAAAC,EAAa,WAAAC,MAAe,QACrC,OAAS,WAAAC,MAAe,qBAmBpB,cAAAC,MAAA,oBARG,SAASC,EAA+B,CAC7C,SAAAC,EACA,OAAAC,CACF,EAGG,CACD,OACEH,EAACJ,EAAA,CAAuB,OAAQO,EAAQ,QAASC,EAC9C,SAAAF,EACH,CAEJ,CAEA,SAASE,GAAyB,CAChC,GAAM,CAAE,gBAAAC,EAAiB,KAAAC,EAAM,UAAAC,EAAW,aAAAC,CAAa,EAAIT,EAAQ,EAC7DU,EAAUH,GAAM,SAChBI,EAAmBb,EACvB,MAAO,CAAE,kBAAmBc,CAAQ,IAAsC,CACxE,GAAI,CAKF,OAAOF,GAAW,IACpB,MAAQ,CACN,OAAO,IACT,CACF,EACA,CAACA,EAASD,CAAY,CACxB,EACA,OAAOV,EACL,KAAO,CACL,UAAAS,EACA,gBAAAF,EACA,iBAAAK,CACF,GACA,CAACH,EAAWF,EAAiBK,CAAgB,CAC/C,CACF","names":["ConvexProviderWithAuth","useCallback","useMemo","useAuth","jsx","ConvexProviderWithHerculesAuth","children","client","useUseAuthFromHercules","isAuthenticated","user","isLoading","signinSilent","idToken","fetchAccessToken","_ignore"]}
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var w=(r,o)=>{for(var e in o)c(r,e,{get:o[e],enumerable:!0})},v=(r,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of A(o))!_.call(r,i)&&i!==e&&c(r,i,{get:()=>o[i],enumerable:!(t=P(o,i))||t.enumerable});return r};var y=r=>v(c({},"__esModule",{value:!0}),r);var C={};w(C,{HerculesAuthProvider:()=>S,hasAuthParams:()=>p.hasAuthParams,useAuth:()=>p.useAuth,useUser:()=>g});module.exports=y(C);var a=require("react"),u=require("react-oidc-context"),n=require("oidc-client-ts"),s=require("react/jsx-runtime");function U(){window.history.replaceState({},document.title,window.location.pathname)}function x(){window.location.pathname=""}var b={onSignoutCallback:x,onSigninCallback:U};function S({children:r,userManagerSettings:o,...e}){let[t]=(0,a.useState)(()=>new n.UserManager({...o,authority:o.authority,client_id:o.client_id,prompt:o.prompt??"select_account",response_type:o.response_type??"code",scope:o.scope??"openid profile email offline_access",redirect_uri:o.redirect_uri??`${window.location.origin}/auth/callback`,post_logout_redirect_uri:o.post_logout_redirect_uri??window.location.origin,userStore:o.userStore??new n.WebStorageStateStore({store:window.localStorage})}));return(0,s.jsx)(u.AuthProvider,{userManager:t,...b,...e,children:r})}var l=require("react"),d=require("react-oidc-context");function g(){let{user:r,isLoading:o,error:e,isAuthenticated:t}=(0,d.useAuth)();return(0,l.useMemo)(()=>{let i=r?.profile.sub,m=r?.profile.name,h=r?.profile.email,f=r?.profile.picture;return{...r??{},id:i,name:m,email:h,avatar:f,isAuthenticated:t,isLoading:o,error:e}},[r,t,o,e])}var p=require("react-oidc-context");0&&(module.exports={HerculesAuthProvider,hasAuthParams,useAuth,useUser});
1
+ "use strict";var s=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var _=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},y=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!P.call(t,r)&&r!==o&&s(t,r,{get:()=>e[r],enumerable:!(i=w(e,r))||i.enumerable});return t};var v=t=>y(s({},"__esModule",{value:!0}),t);var L={};_(L,{HerculesAuthProvider:()=>H,hasAuthParams:()=>c.hasAuthParams,useAuth:()=>c.useAuth,useUser:()=>k});module.exports=v(L);var g=require("react"),x=require("react-oidc-context"),S=require("react/jsx-runtime");var u=require("react"),l=require("react-oidc-context"),n=require("oidc-client-ts"),p=require("react/jsx-runtime");function U(){window.history.replaceState({},document.title,window.location.pathname)}function b(){window.location.pathname=""}var C={onSignoutCallback:b,onSigninCallback:U};function H({children:t,userManagerSettings:e,authority:o,client_id:i,...r}){let[a]=(0,u.useState)(()=>new n.UserManager({...e,authority:e?.authority??o,client_id:e?.client_id??i,prompt:e?.prompt??"select_account",response_type:e?.response_type??"code",scope:e?.scope??"openid profile email offline_access",redirect_uri:e?.redirect_uri??`${window.location.origin}/auth/callback`,post_logout_redirect_uri:e?.post_logout_redirect_uri??window.location.origin,userStore:e?.userStore??new n.WebStorageStateStore({store:window.localStorage})}));return(0,p.jsx)(l.AuthProvider,{userManager:a,...C,...r,children:t})}var d=require("react"),h=require("react-oidc-context");function k(){let{user:t,isLoading:e,error:o,isAuthenticated:i}=(0,h.useAuth)();return(0,d.useMemo)(()=>{let r=t?.profile.sub,a=t?.profile.name,m=t?.profile.email,f=t?.profile.picture;return{...t??{},id:r,name:a,email:m,avatar:f,isAuthenticated:i,isLoading:e,error:o}},[t,i,e,o])}var c=require("react-oidc-context");0&&(module.exports={HerculesAuthProvider,hasAuthParams,useAuth,useUser});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/index.ts","../../src/react/HerculesAuthProvider.tsx","../../src/react/use-user.ts"],"sourcesContent":["export * from \"./HerculesAuthProvider\";\nexport * from \"./use-user\";\n\n// rexports of react-oidc-context\nexport {\n useAuth,\n type AuthContextProps,\n hasAuthParams,\n} from \"react-oidc-context\";\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n AuthProvider as ReactAuthProvider,\n type AuthProviderProps,\n type AuthProviderUserManagerProps,\n} from \"react-oidc-context\";\nimport {\n UserManager,\n WebStorageStateStore,\n type UserManagerSettings,\n} from \"oidc-client-ts\";\n\nfunction onSigninCallback() {\n window.history.replaceState({}, document.title, window.location.pathname);\n}\n\nfunction onSignoutCallback() {\n window.location.pathname = \"\";\n}\n\nconst DEFAULT_AUTH_CONFIG: Partial<AuthProviderProps> = {\n onSignoutCallback,\n onSigninCallback,\n};\n\nexport type HerculesAuthProviderProps = AuthProviderUserManagerProps & {\n userManagerSettings: UserManagerSettings;\n};\n\n/**\n * A wrapper React component which provides a {@link ReactAuthProvider}\n * configured with Hercules Auth.\n *\n * @public\n */\nexport function HerculesAuthProvider({\n children,\n userManagerSettings,\n ...props\n}: HerculesAuthProviderProps) {\n const [userManager] = useState(\n () =>\n new UserManager({\n ...userManagerSettings,\n authority: userManagerSettings.authority,\n client_id: userManagerSettings.client_id,\n prompt: userManagerSettings.prompt ?? \"select_account\",\n response_type: userManagerSettings.response_type ?? \"code\",\n scope:\n userManagerSettings.scope ?? \"openid profile email offline_access\",\n redirect_uri:\n userManagerSettings.redirect_uri ??\n `${window.location.origin}/auth/callback`,\n post_logout_redirect_uri:\n userManagerSettings.post_logout_redirect_uri ??\n window.location.origin,\n userStore:\n userManagerSettings.userStore ??\n new WebStorageStateStore({ store: window.localStorage }),\n \n }),\n );\n\n return (\n <ReactAuthProvider\n userManager={userManager}\n {...DEFAULT_AUTH_CONFIG}\n {...props}\n >\n {children}\n </ReactAuthProvider>\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\n\n/**\n * A hook that returns the current user if authenticated\n *\n * @public\n */\nexport function useUser() {\n const { user, isLoading, error, isAuthenticated } = useAuth();\n\n return useMemo(() => {\n const id = user?.profile.sub;\n const name = user?.profile.name;\n const email = user?.profile.email;\n const avatar = user?.profile.picture;\n return {\n ...(user ?? {}),\n id,\n name,\n email,\n avatar,\n isAuthenticated,\n isLoading,\n error,\n };\n }, [user, isAuthenticated, isLoading, error]);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,oEAAAC,IAAA,eAAAC,EAAAJ,GCEA,IAAAK,EAAyB,iBACzBC,EAIO,8BACPC,EAIO,0BAsDHC,EAAA,6BApDJ,SAASC,GAAmB,CAC1B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAO,OAAO,SAAS,QAAQ,CAC1E,CAEA,SAASC,GAAoB,CAC3B,OAAO,SAAS,SAAW,EAC7B,CAEA,IAAMC,EAAkD,CACtD,kBAAAD,EACA,iBAAAD,CACF,EAYO,SAASG,EAAqB,CACnC,SAAAC,EACA,oBAAAC,EACA,GAAGC,CACL,EAA8B,CAC5B,GAAM,CAACC,CAAW,KAAI,YACpB,IACE,IAAI,cAAY,CACd,GAAGF,EACH,UAAWA,EAAoB,UAC/B,UAAWA,EAAoB,UAC/B,OAAQA,EAAoB,QAAU,iBACtC,cAAeA,EAAoB,eAAiB,OACpD,MACEA,EAAoB,OAAS,sCAC/B,aACEA,EAAoB,cACpB,GAAG,OAAO,SAAS,MAAM,iBAC3B,yBACEA,EAAoB,0BACpB,OAAO,SAAS,OAClB,UACEA,EAAoB,WACpB,IAAI,uBAAqB,CAAE,MAAO,OAAO,YAAa,CAAC,CAE3D,CAAC,CACL,EAEA,SACE,OAAC,EAAAG,aAAA,CACC,YAAaD,EACZ,GAAGL,EACH,GAAGI,EAEH,SAAAF,EACH,CAEJ,CCxEA,IAAAK,EAAwB,iBACxBC,EAAwB,8BAOjB,SAASC,GAAU,CACxB,GAAM,CAAE,KAAAC,EAAM,UAAAC,EAAW,MAAAC,EAAO,gBAAAC,CAAgB,KAAI,WAAQ,EAE5D,SAAO,WAAQ,IAAM,CACnB,IAAMC,EAAKJ,GAAM,QAAQ,IACnBK,EAAOL,GAAM,QAAQ,KACrBM,EAAQN,GAAM,QAAQ,MACtBO,EAASP,GAAM,QAAQ,QAC7B,MAAO,CACL,GAAIA,GAAQ,CAAC,EACb,GAAAI,EACA,KAAAC,EACA,MAAAC,EACA,OAAAC,EACA,gBAAAJ,EACA,UAAAF,EACA,MAAAC,CACF,CACF,EAAG,CAACF,EAAMG,EAAiBF,EAAWC,CAAK,CAAC,CAC9C,CFzBA,IAAAM,EAIO","names":["react_exports","__export","HerculesAuthProvider","useUser","__toCommonJS","import_react","import_react_oidc_context","import_oidc_client_ts","import_jsx_runtime","onSigninCallback","onSignoutCallback","DEFAULT_AUTH_CONFIG","HerculesAuthProvider","children","userManagerSettings","props","userManager","ReactAuthProvider","import_react","import_react_oidc_context","useUser","user","isLoading","error","isAuthenticated","id","name","email","avatar","import_react_oidc_context"]}
1
+ {"version":3,"sources":["../../src/react/index.ts","../../src/react/AuthCallbackPage.tsx","../../src/react/HerculesAuthProvider.tsx","../../src/react/use-user.ts"],"sourcesContent":["export * from \"./AuthCallbackPage\";\nexport * from \"./HerculesAuthProvider\";\nexport * from \"./use-user\";\n\n// rexports of react-oidc-context\nexport {\n type AuthContextProps,\n hasAuthParams,\n useAuth,\n} from \"react-oidc-context\";\n","import { useEffect } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\n\nexport default function AuthCallback() {\n const { isLoading, isAuthenticated, error } = useAuth();\n\n useEffect(() => {\n // Redirect to home after auth completes\n if (!isLoading && isAuthenticated) {\n window.history.replaceState({}, document.title, \"/\");\n }\n // Handle auth errors\n else if (!isLoading && error) {\n console.error(\"Authentication error:\", error);\n window.history.replaceState({}, document.title, \"/\");\n }\n // Handle auth cancellation/failure\n else if (!isLoading && !isAuthenticated && !error) {\n console.warn(\n \"Authentication completed without success or explicit error\",\n );\n window.history.replaceState({}, document.title, \"/\");\n }\n }, [isLoading, isAuthenticated, error]);\n\n return (\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n height: \"100vh\",\n }}\n >\n Loading...\n </div>\n );\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n AuthProvider as ReactAuthProvider,\n type AuthProviderUserManagerProps,\n} from \"react-oidc-context\";\nimport {\n UserManager,\n WebStorageStateStore,\n type UserManagerSettings,\n} from \"oidc-client-ts\";\n\nexport type HerculesAuthProviderProps = Omit<\n AuthProviderUserManagerProps,\n \"userManager\"\n> & {\n userManagerSettings?: Partial<UserManagerSettings>;\n authority: string;\n client_id: string;\n};\n\nfunction onSigninCallback() {\n window.history.replaceState({}, document.title, window.location.pathname);\n}\n\nfunction onSignoutCallback() {\n window.location.pathname = \"\";\n}\n\nconst DEFAULT_AUTH_CONFIG: Partial<HerculesAuthProviderProps> = {\n onSignoutCallback,\n onSigninCallback,\n};\n\n/**\n * A wrapper React component which provides a {@link ReactAuthProvider}\n * configured with Hercules Auth.\n *\n * @public\n */\nexport function HerculesAuthProvider({\n children,\n userManagerSettings,\n authority,\n client_id,\n ...props\n}: HerculesAuthProviderProps) {\n const [userManager] = useState(\n () =>\n new UserManager({\n ...userManagerSettings,\n authority: userManagerSettings?.authority ?? authority,\n client_id: userManagerSettings?.client_id ?? client_id,\n prompt: userManagerSettings?.prompt ?? \"select_account\",\n response_type: userManagerSettings?.response_type ?? \"code\",\n scope:\n userManagerSettings?.scope ?? \"openid profile email offline_access\",\n redirect_uri:\n userManagerSettings?.redirect_uri ??\n `${window.location.origin}/auth/callback`,\n post_logout_redirect_uri:\n userManagerSettings?.post_logout_redirect_uri ??\n window.location.origin,\n userStore:\n userManagerSettings?.userStore ??\n new WebStorageStateStore({ store: window.localStorage }),\n }),\n );\n\n return (\n <ReactAuthProvider\n userManager={userManager}\n {...DEFAULT_AUTH_CONFIG}\n {...props}\n >\n {children}\n </ReactAuthProvider>\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\n\n/**\n * A hook that returns the current user if authenticated\n *\n * @public\n */\nexport function useUser() {\n const { user, isLoading, error, isAuthenticated } = useAuth();\n\n return useMemo(() => {\n const id = user?.profile.sub;\n const name = user?.profile.name;\n const email = user?.profile.email;\n const avatar = user?.profile.picture;\n return {\n ...(user ?? {}),\n id,\n name,\n email,\n avatar,\n isAuthenticated,\n isLoading,\n error,\n };\n }, [user, isAuthenticated, isLoading, error]);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,oEAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAA0B,iBAC1BC,EAAwB,8BAyBpBC,EAAA,6BCxBJ,IAAAC,EAAyB,iBACzBC,EAGO,8BACPC,EAIO,0BA4DHC,EAAA,6BAjDJ,SAASC,GAAmB,CAC1B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAO,OAAO,SAAS,QAAQ,CAC1E,CAEA,SAASC,GAAoB,CAC3B,OAAO,SAAS,SAAW,EAC7B,CAEA,IAAMC,EAA0D,CAC9D,kBAAAD,EACA,iBAAAD,CACF,EAQO,SAASG,EAAqB,CACnC,SAAAC,EACA,oBAAAC,EACA,UAAAC,EACA,UAAAC,EACA,GAAGC,CACL,EAA8B,CAC5B,GAAM,CAACC,CAAW,KAAI,YACpB,IACE,IAAI,cAAY,CACd,GAAGJ,EACH,UAAWA,GAAqB,WAAaC,EAC7C,UAAWD,GAAqB,WAAaE,EAC7C,OAAQF,GAAqB,QAAU,iBACvC,cAAeA,GAAqB,eAAiB,OACrD,MACEA,GAAqB,OAAS,sCAChC,aACEA,GAAqB,cACrB,GAAG,OAAO,SAAS,MAAM,iBAC3B,yBACEA,GAAqB,0BACrB,OAAO,SAAS,OAClB,UACEA,GAAqB,WACrB,IAAI,uBAAqB,CAAE,MAAO,OAAO,YAAa,CAAC,CAC3D,CAAC,CACL,EAEA,SACE,OAAC,EAAAK,aAAA,CACC,YAAaD,EACZ,GAAGP,EACH,GAAGM,EAEH,SAAAJ,EACH,CAEJ,CC7EA,IAAAO,EAAwB,iBACxBC,EAAwB,8BAOjB,SAASC,GAAU,CACxB,GAAM,CAAE,KAAAC,EAAM,UAAAC,EAAW,MAAAC,EAAO,gBAAAC,CAAgB,KAAI,WAAQ,EAE5D,SAAO,WAAQ,IAAM,CACnB,IAAMC,EAAKJ,GAAM,QAAQ,IACnBK,EAAOL,GAAM,QAAQ,KACrBM,EAAQN,GAAM,QAAQ,MACtBO,EAASP,GAAM,QAAQ,QAC7B,MAAO,CACL,GAAIA,GAAQ,CAAC,EACb,GAAAI,EACA,KAAAC,EACA,MAAAC,EACA,OAAAC,EACA,gBAAAJ,EACA,UAAAF,EACA,MAAAC,CACF,CACF,EAAG,CAACF,EAAMG,EAAiBF,EAAWC,CAAK,CAAC,CAC9C,CHxBA,IAAAM,EAIO","names":["react_exports","__export","HerculesAuthProvider","useUser","__toCommonJS","import_react","import_react_oidc_context","import_jsx_runtime","import_react","import_react_oidc_context","import_oidc_client_ts","import_jsx_runtime","onSigninCallback","onSignoutCallback","DEFAULT_AUTH_CONFIG","HerculesAuthProvider","children","userManagerSettings","authority","client_id","props","userManager","ReactAuthProvider","import_react","import_react_oidc_context","useUser","user","isLoading","error","isAuthenticated","id","name","email","avatar","import_react_oidc_context"]}
@@ -5,10 +5,12 @@ export { AuthContextProps, hasAuthParams, useAuth } from 'react-oidc-context';
5
5
  import * as oidc_client_ts from 'oidc-client-ts';
6
6
  import { UserManagerSettings } from 'oidc-client-ts';
7
7
 
8
- type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
9
- userManagerSettings: UserManagerSettings;
8
+ type HerculesAuthProviderProps = Omit<AuthProviderUserManagerProps, "userManager"> & {
9
+ userManagerSettings?: Partial<UserManagerSettings>;
10
+ authority: string;
11
+ client_id: string;
10
12
  };
11
- declare function HerculesAuthProvider({ children, userManagerSettings, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
13
+ declare function HerculesAuthProvider({ children, userManagerSettings, authority, client_id, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
12
14
 
13
15
  declare function useUser(): {
14
16
  id: string | undefined;
@@ -5,10 +5,12 @@ export { AuthContextProps, hasAuthParams, useAuth } from 'react-oidc-context';
5
5
  import * as oidc_client_ts from 'oidc-client-ts';
6
6
  import { UserManagerSettings } from 'oidc-client-ts';
7
7
 
8
- type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
9
- userManagerSettings: UserManagerSettings;
8
+ type HerculesAuthProviderProps = Omit<AuthProviderUserManagerProps, "userManager"> & {
9
+ userManagerSettings?: Partial<UserManagerSettings>;
10
+ authority: string;
11
+ client_id: string;
10
12
  };
11
- declare function HerculesAuthProvider({ children, userManagerSettings, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
13
+ declare function HerculesAuthProvider({ children, userManagerSettings, authority, client_id, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
12
14
 
13
15
  declare function useUser(): {
14
16
  id: string | undefined;
@@ -1,2 +1,2 @@
1
- import{useState as a}from"react";import{AuthProvider as u}from"react-oidc-context";import{UserManager as s,WebStorageStateStore as l}from"oidc-client-ts";import{jsx as f}from"react/jsx-runtime";function d(){window.history.replaceState({},document.title,window.location.pathname)}function m(){window.location.pathname=""}var h={onSignoutCallback:m,onSigninCallback:d};function y({children:r,userManagerSettings:o,...e}){let[t]=a(()=>new s({...o,authority:o.authority,client_id:o.client_id,prompt:o.prompt??"select_account",response_type:o.response_type??"code",scope:o.scope??"openid profile email offline_access",redirect_uri:o.redirect_uri??`${window.location.origin}/auth/callback`,post_logout_redirect_uri:o.post_logout_redirect_uri??window.location.origin,userStore:o.userStore??new l({store:window.localStorage})}));return f(u,{userManager:t,...h,...e,children:r})}import{useMemo as P}from"react";import{useAuth as A}from"react-oidc-context";function g(){let{user:r,isLoading:o,error:e,isAuthenticated:t}=A();return P(()=>{let i=r?.profile.sub,n=r?.profile.name,p=r?.profile.email,c=r?.profile.picture;return{...r??{},id:i,name:n,email:p,avatar:c,isAuthenticated:t,isLoading:o,error:e}},[r,t,o,e])}import{useAuth as R,hasAuthParams as T}from"react-oidc-context";export{y as HerculesAuthProvider,T as hasAuthParams,R as useAuth,g as useUser};
1
+ import{useEffect as _}from"react";import{useAuth as v}from"react-oidc-context";import{jsx as x}from"react/jsx-runtime";import{useState as s}from"react";import{AuthProvider as u}from"react-oidc-context";import{UserManager as l,WebStorageStateStore as p}from"oidc-client-ts";import{jsx as f}from"react/jsx-runtime";function d(){window.history.replaceState({},document.title,window.location.pathname)}function h(){window.location.pathname=""}var m={onSignoutCallback:h,onSigninCallback:d};function H({children:t,userManagerSettings:e,authority:o,client_id:r,...i}){let[n]=s(()=>new l({...e,authority:e?.authority??o,client_id:e?.client_id??r,prompt:e?.prompt??"select_account",response_type:e?.response_type??"code",scope:e?.scope??"openid profile email offline_access",redirect_uri:e?.redirect_uri??`${window.location.origin}/auth/callback`,post_logout_redirect_uri:e?.post_logout_redirect_uri??window.location.origin,userStore:e?.userStore??new p({store:window.localStorage})}));return f(u,{userManager:n,...m,...i,children:t})}import{useMemo as w}from"react";import{useAuth as A}from"react-oidc-context";function I(){let{user:t,isLoading:e,error:o,isAuthenticated:r}=A();return w(()=>{let i=t?.profile.sub,n=t?.profile.name,c=t?.profile.email,a=t?.profile.picture;return{...t??{},id:i,name:n,email:c,avatar:a,isAuthenticated:r,isLoading:e,error:o}},[t,r,e,o])}import{hasAuthParams as N,useAuth as W}from"react-oidc-context";export{H as HerculesAuthProvider,N as hasAuthParams,W as useAuth,I as useUser};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/HerculesAuthProvider.tsx","../../src/react/use-user.ts","../../src/react/index.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport {\n AuthProvider as ReactAuthProvider,\n type AuthProviderProps,\n type AuthProviderUserManagerProps,\n} from \"react-oidc-context\";\nimport {\n UserManager,\n WebStorageStateStore,\n type UserManagerSettings,\n} from \"oidc-client-ts\";\n\nfunction onSigninCallback() {\n window.history.replaceState({}, document.title, window.location.pathname);\n}\n\nfunction onSignoutCallback() {\n window.location.pathname = \"\";\n}\n\nconst DEFAULT_AUTH_CONFIG: Partial<AuthProviderProps> = {\n onSignoutCallback,\n onSigninCallback,\n};\n\nexport type HerculesAuthProviderProps = AuthProviderUserManagerProps & {\n userManagerSettings: UserManagerSettings;\n};\n\n/**\n * A wrapper React component which provides a {@link ReactAuthProvider}\n * configured with Hercules Auth.\n *\n * @public\n */\nexport function HerculesAuthProvider({\n children,\n userManagerSettings,\n ...props\n}: HerculesAuthProviderProps) {\n const [userManager] = useState(\n () =>\n new UserManager({\n ...userManagerSettings,\n authority: userManagerSettings.authority,\n client_id: userManagerSettings.client_id,\n prompt: userManagerSettings.prompt ?? \"select_account\",\n response_type: userManagerSettings.response_type ?? \"code\",\n scope:\n userManagerSettings.scope ?? \"openid profile email offline_access\",\n redirect_uri:\n userManagerSettings.redirect_uri ??\n `${window.location.origin}/auth/callback`,\n post_logout_redirect_uri:\n userManagerSettings.post_logout_redirect_uri ??\n window.location.origin,\n userStore:\n userManagerSettings.userStore ??\n new WebStorageStateStore({ store: window.localStorage }),\n \n }),\n );\n\n return (\n <ReactAuthProvider\n userManager={userManager}\n {...DEFAULT_AUTH_CONFIG}\n {...props}\n >\n {children}\n </ReactAuthProvider>\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\n\n/**\n * A hook that returns the current user if authenticated\n *\n * @public\n */\nexport function useUser() {\n const { user, isLoading, error, isAuthenticated } = useAuth();\n\n return useMemo(() => {\n const id = user?.profile.sub;\n const name = user?.profile.name;\n const email = user?.profile.email;\n const avatar = user?.profile.picture;\n return {\n ...(user ?? {}),\n id,\n name,\n email,\n avatar,\n isAuthenticated,\n isLoading,\n error,\n };\n }, [user, isAuthenticated, isLoading, error]);\n}\n","export * from \"./HerculesAuthProvider\";\nexport * from \"./use-user\";\n\n// rexports of react-oidc-context\nexport {\n useAuth,\n type AuthContextProps,\n hasAuthParams,\n} from \"react-oidc-context\";\n"],"mappings":"AAEA,OAAS,YAAAA,MAAgB,QACzB,OACE,gBAAgBC,MAGX,qBACP,OACE,eAAAC,EACA,wBAAAC,MAEK,iBAsDH,cAAAC,MAAA,oBApDJ,SAASC,GAAmB,CAC1B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAO,OAAO,SAAS,QAAQ,CAC1E,CAEA,SAASC,GAAoB,CAC3B,OAAO,SAAS,SAAW,EAC7B,CAEA,IAAMC,EAAkD,CACtD,kBAAAD,EACA,iBAAAD,CACF,EAYO,SAASG,EAAqB,CACnC,SAAAC,EACA,oBAAAC,EACA,GAAGC,CACL,EAA8B,CAC5B,GAAM,CAACC,CAAW,EAAIZ,EACpB,IACE,IAAIE,EAAY,CACd,GAAGQ,EACH,UAAWA,EAAoB,UAC/B,UAAWA,EAAoB,UAC/B,OAAQA,EAAoB,QAAU,iBACtC,cAAeA,EAAoB,eAAiB,OACpD,MACEA,EAAoB,OAAS,sCAC/B,aACEA,EAAoB,cACpB,GAAG,OAAO,SAAS,MAAM,iBAC3B,yBACEA,EAAoB,0BACpB,OAAO,SAAS,OAClB,UACEA,EAAoB,WACpB,IAAIP,EAAqB,CAAE,MAAO,OAAO,YAAa,CAAC,CAE3D,CAAC,CACL,EAEA,OACEC,EAACH,EAAA,CACC,YAAaW,EACZ,GAAGL,EACH,GAAGI,EAEH,SAAAF,EACH,CAEJ,CCxEA,OAAS,WAAAI,MAAe,QACxB,OAAS,WAAAC,MAAe,qBAOjB,SAASC,GAAU,CACxB,GAAM,CAAE,KAAAC,EAAM,UAAAC,EAAW,MAAAC,EAAO,gBAAAC,CAAgB,EAAIL,EAAQ,EAE5D,OAAOD,EAAQ,IAAM,CACnB,IAAMO,EAAKJ,GAAM,QAAQ,IACnBK,EAAOL,GAAM,QAAQ,KACrBM,EAAQN,GAAM,QAAQ,MACtBO,EAASP,GAAM,QAAQ,QAC7B,MAAO,CACL,GAAIA,GAAQ,CAAC,EACb,GAAAI,EACA,KAAAC,EACA,MAAAC,EACA,OAAAC,EACA,gBAAAJ,EACA,UAAAF,EACA,MAAAC,CACF,CACF,EAAG,CAACF,EAAMG,EAAiBF,EAAWC,CAAK,CAAC,CAC9C,CCzBA,OACE,WAAAM,EAEA,iBAAAC,MACK","names":["useState","ReactAuthProvider","UserManager","WebStorageStateStore","jsx","onSigninCallback","onSignoutCallback","DEFAULT_AUTH_CONFIG","HerculesAuthProvider","children","userManagerSettings","props","userManager","useMemo","useAuth","useUser","user","isLoading","error","isAuthenticated","id","name","email","avatar","useAuth","hasAuthParams"]}
1
+ {"version":3,"sources":["../../src/react/AuthCallbackPage.tsx","../../src/react/HerculesAuthProvider.tsx","../../src/react/use-user.ts","../../src/react/index.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\n\nexport default function AuthCallback() {\n const { isLoading, isAuthenticated, error } = useAuth();\n\n useEffect(() => {\n // Redirect to home after auth completes\n if (!isLoading && isAuthenticated) {\n window.history.replaceState({}, document.title, \"/\");\n }\n // Handle auth errors\n else if (!isLoading && error) {\n console.error(\"Authentication error:\", error);\n window.history.replaceState({}, document.title, \"/\");\n }\n // Handle auth cancellation/failure\n else if (!isLoading && !isAuthenticated && !error) {\n console.warn(\n \"Authentication completed without success or explicit error\",\n );\n window.history.replaceState({}, document.title, \"/\");\n }\n }, [isLoading, isAuthenticated, error]);\n\n return (\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n height: \"100vh\",\n }}\n >\n Loading...\n </div>\n );\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n AuthProvider as ReactAuthProvider,\n type AuthProviderUserManagerProps,\n} from \"react-oidc-context\";\nimport {\n UserManager,\n WebStorageStateStore,\n type UserManagerSettings,\n} from \"oidc-client-ts\";\n\nexport type HerculesAuthProviderProps = Omit<\n AuthProviderUserManagerProps,\n \"userManager\"\n> & {\n userManagerSettings?: Partial<UserManagerSettings>;\n authority: string;\n client_id: string;\n};\n\nfunction onSigninCallback() {\n window.history.replaceState({}, document.title, window.location.pathname);\n}\n\nfunction onSignoutCallback() {\n window.location.pathname = \"\";\n}\n\nconst DEFAULT_AUTH_CONFIG: Partial<HerculesAuthProviderProps> = {\n onSignoutCallback,\n onSigninCallback,\n};\n\n/**\n * A wrapper React component which provides a {@link ReactAuthProvider}\n * configured with Hercules Auth.\n *\n * @public\n */\nexport function HerculesAuthProvider({\n children,\n userManagerSettings,\n authority,\n client_id,\n ...props\n}: HerculesAuthProviderProps) {\n const [userManager] = useState(\n () =>\n new UserManager({\n ...userManagerSettings,\n authority: userManagerSettings?.authority ?? authority,\n client_id: userManagerSettings?.client_id ?? client_id,\n prompt: userManagerSettings?.prompt ?? \"select_account\",\n response_type: userManagerSettings?.response_type ?? \"code\",\n scope:\n userManagerSettings?.scope ?? \"openid profile email offline_access\",\n redirect_uri:\n userManagerSettings?.redirect_uri ??\n `${window.location.origin}/auth/callback`,\n post_logout_redirect_uri:\n userManagerSettings?.post_logout_redirect_uri ??\n window.location.origin,\n userStore:\n userManagerSettings?.userStore ??\n new WebStorageStateStore({ store: window.localStorage }),\n }),\n );\n\n return (\n <ReactAuthProvider\n userManager={userManager}\n {...DEFAULT_AUTH_CONFIG}\n {...props}\n >\n {children}\n </ReactAuthProvider>\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport { useAuth } from \"react-oidc-context\";\n\n/**\n * A hook that returns the current user if authenticated\n *\n * @public\n */\nexport function useUser() {\n const { user, isLoading, error, isAuthenticated } = useAuth();\n\n return useMemo(() => {\n const id = user?.profile.sub;\n const name = user?.profile.name;\n const email = user?.profile.email;\n const avatar = user?.profile.picture;\n return {\n ...(user ?? {}),\n id,\n name,\n email,\n avatar,\n isAuthenticated,\n isLoading,\n error,\n };\n }, [user, isAuthenticated, isLoading, error]);\n}\n","export * from \"./AuthCallbackPage\";\nexport * from \"./HerculesAuthProvider\";\nexport * from \"./use-user\";\n\n// rexports of react-oidc-context\nexport {\n type AuthContextProps,\n hasAuthParams,\n useAuth,\n} from \"react-oidc-context\";\n"],"mappings":"AAAA,OAAS,aAAAA,MAAiB,QAC1B,OAAS,WAAAC,MAAe,qBAyBpB,cAAAC,MAAA,oBCxBJ,OAAS,YAAAC,MAAgB,QACzB,OACE,gBAAgBC,MAEX,qBACP,OACE,eAAAC,EACA,wBAAAC,MAEK,iBA4DH,cAAAC,MAAA,oBAjDJ,SAASC,GAAmB,CAC1B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAO,OAAO,SAAS,QAAQ,CAC1E,CAEA,SAASC,GAAoB,CAC3B,OAAO,SAAS,SAAW,EAC7B,CAEA,IAAMC,EAA0D,CAC9D,kBAAAD,EACA,iBAAAD,CACF,EAQO,SAASG,EAAqB,CACnC,SAAAC,EACA,oBAAAC,EACA,UAAAC,EACA,UAAAC,EACA,GAAGC,CACL,EAA8B,CAC5B,GAAM,CAACC,CAAW,EAAId,EACpB,IACE,IAAIE,EAAY,CACd,GAAGQ,EACH,UAAWA,GAAqB,WAAaC,EAC7C,UAAWD,GAAqB,WAAaE,EAC7C,OAAQF,GAAqB,QAAU,iBACvC,cAAeA,GAAqB,eAAiB,OACrD,MACEA,GAAqB,OAAS,sCAChC,aACEA,GAAqB,cACrB,GAAG,OAAO,SAAS,MAAM,iBAC3B,yBACEA,GAAqB,0BACrB,OAAO,SAAS,OAClB,UACEA,GAAqB,WACrB,IAAIP,EAAqB,CAAE,MAAO,OAAO,YAAa,CAAC,CAC3D,CAAC,CACL,EAEA,OACEC,EAACH,EAAA,CACC,YAAaa,EACZ,GAAGP,EACH,GAAGM,EAEH,SAAAJ,EACH,CAEJ,CC7EA,OAAS,WAAAM,MAAe,QACxB,OAAS,WAAAC,MAAe,qBAOjB,SAASC,GAAU,CACxB,GAAM,CAAE,KAAAC,EAAM,UAAAC,EAAW,MAAAC,EAAO,gBAAAC,CAAgB,EAAIL,EAAQ,EAE5D,OAAOD,EAAQ,IAAM,CACnB,IAAMO,EAAKJ,GAAM,QAAQ,IACnBK,EAAOL,GAAM,QAAQ,KACrBM,EAAQN,GAAM,QAAQ,MACtBO,EAASP,GAAM,QAAQ,QAC7B,MAAO,CACL,GAAIA,GAAQ,CAAC,EACb,GAAAI,EACA,KAAAC,EACA,MAAAC,EACA,OAAAC,EACA,gBAAAJ,EACA,UAAAF,EACA,MAAAC,CACF,CACF,EAAG,CAACF,EAAMG,EAAiBF,EAAWC,CAAK,CAAC,CAC9C,CCxBA,OAEE,iBAAAM,EACA,WAAAC,MACK","names":["useEffect","useAuth","jsx","useState","ReactAuthProvider","UserManager","WebStorageStateStore","jsx","onSigninCallback","onSignoutCallback","DEFAULT_AUTH_CONFIG","HerculesAuthProvider","children","userManagerSettings","authority","client_id","props","userManager","useMemo","useAuth","useUser","user","isLoading","error","isAuthenticated","id","name","email","avatar","hasAuthParams","useAuth"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usehercules/auth",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "Authentication utilities for Hercules applications using OIDC",
5
5
  "type": "module",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "convex": "^1.29.2",
33
+ "convex": "^1.29.3",
34
34
  "oidc-client-ts": "^3.4.1",
35
35
  "react-oidc-context": "^3.3.0"
36
36
  },
@@ -38,10 +38,8 @@
38
38
  "react": "^18.0.0 || ^19.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/react": "^18.3.26",
42
- "@types/react-dom": "^18.3.7",
43
- "react": "^18.3.1",
44
- "react-dom": "^18.3.1",
41
+ "@types/react": "^19.2.6",
42
+ "react": "^19.2.0",
45
43
  "tsup": "^8.5.1",
46
44
  "typescript": "^5.9.3"
47
45
  },
@@ -32,12 +32,12 @@ function useUseAuthFromHercules() {
32
32
  const { isAuthenticated, user, isLoading, signinSilent } = useAuth();
33
33
  const idToken = user?.id_token;
34
34
  const fetchAccessToken = useCallback(
35
- async ({ forceRefreshToken }: { forceRefreshToken: boolean }) => {
35
+ async ({ forceRefreshToken: _ignore }: { forceRefreshToken: boolean }) => {
36
36
  try {
37
- if (forceRefreshToken) {
38
- const user = await signinSilent();
39
- return user?.id_token ?? null;
40
- }
37
+ // if (forceRefreshToken) {
38
+ // const user = await signinSilent();
39
+ // return user?.id_token ?? null;
40
+ // }
41
41
  return idToken ?? null;
42
42
  } catch {
43
43
  return null;
@@ -0,0 +1,38 @@
1
+ import { useEffect } from "react";
2
+ import { useAuth } from "react-oidc-context";
3
+
4
+ export default function AuthCallback() {
5
+ const { isLoading, isAuthenticated, error } = useAuth();
6
+
7
+ useEffect(() => {
8
+ // Redirect to home after auth completes
9
+ if (!isLoading && isAuthenticated) {
10
+ window.history.replaceState({}, document.title, "/");
11
+ }
12
+ // Handle auth errors
13
+ else if (!isLoading && error) {
14
+ console.error("Authentication error:", error);
15
+ window.history.replaceState({}, document.title, "/");
16
+ }
17
+ // Handle auth cancellation/failure
18
+ else if (!isLoading && !isAuthenticated && !error) {
19
+ console.warn(
20
+ "Authentication completed without success or explicit error",
21
+ );
22
+ window.history.replaceState({}, document.title, "/");
23
+ }
24
+ }, [isLoading, isAuthenticated, error]);
25
+
26
+ return (
27
+ <div
28
+ style={{
29
+ display: "flex",
30
+ alignItems: "center",
31
+ justifyContent: "center",
32
+ height: "100vh",
33
+ }}
34
+ >
35
+ Loading...
36
+ </div>
37
+ );
38
+ }
@@ -3,7 +3,6 @@
3
3
  import { useState } from "react";
4
4
  import {
5
5
  AuthProvider as ReactAuthProvider,
6
- type AuthProviderProps,
7
6
  type AuthProviderUserManagerProps,
8
7
  } from "react-oidc-context";
9
8
  import {
@@ -12,6 +11,15 @@ import {
12
11
  type UserManagerSettings,
13
12
  } from "oidc-client-ts";
14
13
 
14
+ export type HerculesAuthProviderProps = Omit<
15
+ AuthProviderUserManagerProps,
16
+ "userManager"
17
+ > & {
18
+ userManagerSettings?: Partial<UserManagerSettings>;
19
+ authority: string;
20
+ client_id: string;
21
+ };
22
+
15
23
  function onSigninCallback() {
16
24
  window.history.replaceState({}, document.title, window.location.pathname);
17
25
  }
@@ -20,15 +28,11 @@ function onSignoutCallback() {
20
28
  window.location.pathname = "";
21
29
  }
22
30
 
23
- const DEFAULT_AUTH_CONFIG: Partial<AuthProviderProps> = {
31
+ const DEFAULT_AUTH_CONFIG: Partial<HerculesAuthProviderProps> = {
24
32
  onSignoutCallback,
25
33
  onSigninCallback,
26
34
  };
27
35
 
28
- export type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
29
- userManagerSettings: UserManagerSettings;
30
- };
31
-
32
36
  /**
33
37
  * A wrapper React component which provides a {@link ReactAuthProvider}
34
38
  * configured with Hercules Auth.
@@ -38,28 +42,29 @@ export type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
38
42
  export function HerculesAuthProvider({
39
43
  children,
40
44
  userManagerSettings,
45
+ authority,
46
+ client_id,
41
47
  ...props
42
48
  }: HerculesAuthProviderProps) {
43
49
  const [userManager] = useState(
44
50
  () =>
45
51
  new UserManager({
46
52
  ...userManagerSettings,
47
- authority: userManagerSettings.authority,
48
- client_id: userManagerSettings.client_id,
49
- prompt: userManagerSettings.prompt ?? "select_account",
50
- response_type: userManagerSettings.response_type ?? "code",
53
+ authority: userManagerSettings?.authority ?? authority,
54
+ client_id: userManagerSettings?.client_id ?? client_id,
55
+ prompt: userManagerSettings?.prompt ?? "select_account",
56
+ response_type: userManagerSettings?.response_type ?? "code",
51
57
  scope:
52
- userManagerSettings.scope ?? "openid profile email offline_access",
58
+ userManagerSettings?.scope ?? "openid profile email offline_access",
53
59
  redirect_uri:
54
- userManagerSettings.redirect_uri ??
60
+ userManagerSettings?.redirect_uri ??
55
61
  `${window.location.origin}/auth/callback`,
56
62
  post_logout_redirect_uri:
57
- userManagerSettings.post_logout_redirect_uri ??
63
+ userManagerSettings?.post_logout_redirect_uri ??
58
64
  window.location.origin,
59
65
  userStore:
60
- userManagerSettings.userStore ??
66
+ userManagerSettings?.userStore ??
61
67
  new WebStorageStateStore({ store: window.localStorage }),
62
-
63
68
  }),
64
69
  );
65
70
 
@@ -1,9 +1,10 @@
1
+ export * from "./AuthCallbackPage";
1
2
  export * from "./HerculesAuthProvider";
2
3
  export * from "./use-user";
3
4
 
4
5
  // rexports of react-oidc-context
5
6
  export {
6
- useAuth,
7
7
  type AuthContextProps,
8
8
  hasAuthParams,
9
+ useAuth,
9
10
  } from "react-oidc-context";