@usehercules/auth 1.0.26 → 1.0.27

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 n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var A=(o,e)=>{for(var r in e)n(o,r,{get:e[r],enumerable:!0})},v=(o,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of h(e))!P.call(o,t)&&t!==r&&n(o,t,{get:()=>e[t],enumerable:!(i=f(e,t))||i.enumerable});return o};var w=o=>v(n({},"__esModule",{value:!0}),o);var H={};A(H,{HerculesAuthProvider:()=>g,useAuth:()=>p.useAuth,useUser:()=>y});module.exports=w(H);var u=require("react-oidc-context"),c=require("react/jsx-runtime");function x(){window.history.replaceState({},document.title,window.location.pathname)}function _(){window.location.pathname=""}var b={prompt:"select_account",response_type:"code",scope:"openid profile email",redirect_uri:`${window.location.origin}/auth/callback`,onSigninCallback:x,onSignoutCallback:_};function g(o){return(0,c.jsx)(u.AuthProvider,{...b,...o})}var p=require("react-oidc-context");var s=require("react"),a=require("react-oidc-context");function y(){let{user:o,isLoading:e,error:r,isAuthenticated:i}=(0,a.useAuth)();return(0,s.useMemo)(()=>{let t=o?.profile.sub,l=o?.profile.name,m=o?.profile.email,d=o?.profile.picture;return{...o??{},id:t,name:l,email:m,avatar:d,isAuthenticated:i,isLoading:e,error:r}},[o,i,e,r])}0&&(module.exports={HerculesAuthProvider,useAuth,useUser});
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});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/index.ts","../../src/react/HerculesAuthProvider.tsx","../../src/react/use-auth.ts","../../src/react/use-user.ts"],"sourcesContent":["export * from \"./HerculesAuthProvider\";\nexport * from \"./use-auth\";\nexport * from \"./use-user\";\n","\"use client\";\n\nimport {\n AuthProvider as ReactAuthProvider,\n type AuthProviderProps,\n} from \"react-oidc-context\";\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 prompt: \"select_account\",\n response_type: \"code\",\n scope: \"openid profile email\",\n redirect_uri: `${window.location.origin}/auth/callback`,\n onSigninCallback,\n onSignoutCallback,\n};\n\nexport type HerculesAuthProviderProps = AuthProviderProps;\n\n/**\n * A wrapper React component which provides a {@link ReactAuthProvider}\n * configured with Hercules Auth.\n *\n * @public\n */\nexport function HerculesAuthProvider(props: HerculesAuthProviderProps) {\n return <ReactAuthProvider {...DEFAULT_AUTH_CONFIG} {...props} />;\n}\n","\"use client\";\n\nimport { useAuth } from \"react-oidc-context\";\nexport { useAuth };\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,kCAAAC,IAAA,eAAAC,EAAAJ,GCEA,IAAAK,EAGO,8BA4BEC,EAAA,6BA1BT,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,OAAQ,iBACR,cAAe,OACf,MAAO,uBACP,aAAc,GAAG,OAAO,SAAS,MAAM,iBACvC,iBAAAF,EACA,kBAAAC,CACF,EAUO,SAASE,EAAqBC,EAAkC,CACrE,SAAO,OAAC,EAAAC,aAAA,CAAmB,GAAGH,EAAsB,GAAGE,EAAO,CAChE,CChCA,IAAAE,EAAwB,8BCAxB,IAAAC,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","names":["react_exports","__export","HerculesAuthProvider","useUser","__toCommonJS","import_react_oidc_context","import_jsx_runtime","onSigninCallback","onSignoutCallback","DEFAULT_AUTH_CONFIG","HerculesAuthProvider","props","ReactAuthProvider","import_react_oidc_context","import_react","import_react_oidc_context","useUser","user","isLoading","error","isAuthenticated","id","name","email","avatar"]}
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,11 +1,14 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react_oidc_context from 'react-oidc-context';
3
- import { AuthProviderProps } from 'react-oidc-context';
4
- export { useAuth } from 'react-oidc-context';
3
+ import { AuthProviderUserManagerProps } from 'react-oidc-context';
4
+ export { AuthContextProps, hasAuthParams, useAuth } from 'react-oidc-context';
5
5
  import * as oidc_client_ts from 'oidc-client-ts';
6
+ import { UserManagerSettings } from 'oidc-client-ts';
6
7
 
7
- type HerculesAuthProviderProps = AuthProviderProps;
8
- declare function HerculesAuthProvider(props: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
8
+ type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
9
+ userManagerSettings: UserManagerSettings;
10
+ };
11
+ declare function HerculesAuthProvider({ children, userManagerSettings, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
9
12
 
10
13
  declare function useUser(): {
11
14
  id: string | undefined;
@@ -1,11 +1,14 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react_oidc_context from 'react-oidc-context';
3
- import { AuthProviderProps } from 'react-oidc-context';
4
- export { useAuth } from 'react-oidc-context';
3
+ import { AuthProviderUserManagerProps } from 'react-oidc-context';
4
+ export { AuthContextProps, hasAuthParams, useAuth } from 'react-oidc-context';
5
5
  import * as oidc_client_ts from 'oidc-client-ts';
6
+ import { UserManagerSettings } from 'oidc-client-ts';
6
7
 
7
- type HerculesAuthProviderProps = AuthProviderProps;
8
- declare function HerculesAuthProvider(props: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
8
+ type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
9
+ userManagerSettings: UserManagerSettings;
10
+ };
11
+ declare function HerculesAuthProvider({ children, userManagerSettings, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
9
12
 
10
13
  declare function useUser(): {
11
14
  id: string | undefined;
@@ -1,2 +1,2 @@
1
- import{AuthProvider as p}from"react-oidc-context";import{jsx as m}from"react/jsx-runtime";function s(){window.history.replaceState({},document.title,window.location.pathname)}function a(){window.location.pathname=""}var l={prompt:"select_account",response_type:"code",scope:"openid profile email",redirect_uri:`${window.location.origin}/auth/callback`,onSigninCallback:s,onSignoutCallback:a};function P(o){return m(p,{...l,...o})}import{useAuth as x}from"react-oidc-context";import{useMemo as d}from"react";import{useAuth as f}from"react-oidc-context";function y(){let{user:o,isLoading:e,error:r,isAuthenticated:t}=f();return d(()=>{let i=o?.profile.sub,n=o?.profile.name,u=o?.profile.email,c=o?.profile.picture;return{...o??{},id:i,name:n,email:u,avatar:c,isAuthenticated:t,isLoading:e,error:r}},[o,t,e,r])}export{P as HerculesAuthProvider,x as useAuth,y as useUser};
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};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/HerculesAuthProvider.tsx","../../src/react/use-auth.ts","../../src/react/use-user.ts"],"sourcesContent":["\"use client\";\n\nimport {\n AuthProvider as ReactAuthProvider,\n type AuthProviderProps,\n} from \"react-oidc-context\";\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 prompt: \"select_account\",\n response_type: \"code\",\n scope: \"openid profile email\",\n redirect_uri: `${window.location.origin}/auth/callback`,\n onSigninCallback,\n onSignoutCallback,\n};\n\nexport type HerculesAuthProviderProps = AuthProviderProps;\n\n/**\n * A wrapper React component which provides a {@link ReactAuthProvider}\n * configured with Hercules Auth.\n *\n * @public\n */\nexport function HerculesAuthProvider(props: HerculesAuthProviderProps) {\n return <ReactAuthProvider {...DEFAULT_AUTH_CONFIG} {...props} />;\n}\n","\"use client\";\n\nimport { useAuth } from \"react-oidc-context\";\nexport { useAuth };\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":"AAEA,OACE,gBAAgBA,MAEX,qBA4BE,cAAAC,MAAA,oBA1BT,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,OAAQ,iBACR,cAAe,OACf,MAAO,uBACP,aAAc,GAAG,OAAO,SAAS,MAAM,iBACvC,iBAAAF,EACA,kBAAAC,CACF,EAUO,SAASE,EAAqBC,EAAkC,CACrE,OAAOL,EAACD,EAAA,CAAmB,GAAGI,EAAsB,GAAGE,EAAO,CAChE,CChCA,OAAS,WAAAC,MAAe,qBCAxB,OAAS,WAAAC,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","names":["ReactAuthProvider","jsx","onSigninCallback","onSignoutCallback","DEFAULT_AUTH_CONFIG","HerculesAuthProvider","props","useAuth","useMemo","useAuth","useUser","user","isLoading","error","isAuthenticated","id","name","email","avatar"]}
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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usehercules/auth",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Authentication utilities for Hercules applications using OIDC",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,9 +1,16 @@
1
1
  "use client";
2
2
 
3
+ import { useState } from "react";
3
4
  import {
4
5
  AuthProvider as ReactAuthProvider,
5
6
  type AuthProviderProps,
7
+ type AuthProviderUserManagerProps,
6
8
  } from "react-oidc-context";
9
+ import {
10
+ UserManager,
11
+ WebStorageStateStore,
12
+ type UserManagerSettings,
13
+ } from "oidc-client-ts";
7
14
 
8
15
  function onSigninCallback() {
9
16
  window.history.replaceState({}, document.title, window.location.pathname);
@@ -14,15 +21,13 @@ function onSignoutCallback() {
14
21
  }
15
22
 
16
23
  const DEFAULT_AUTH_CONFIG: Partial<AuthProviderProps> = {
17
- prompt: "select_account",
18
- response_type: "code",
19
- scope: "openid profile email",
20
- redirect_uri: `${window.location.origin}/auth/callback`,
21
- onSigninCallback,
22
24
  onSignoutCallback,
25
+ onSigninCallback,
23
26
  };
24
27
 
25
- export type HerculesAuthProviderProps = AuthProviderProps;
28
+ export type HerculesAuthProviderProps = AuthProviderUserManagerProps & {
29
+ userManagerSettings: UserManagerSettings;
30
+ };
26
31
 
27
32
  /**
28
33
  * A wrapper React component which provides a {@link ReactAuthProvider}
@@ -30,6 +35,41 @@ export type HerculesAuthProviderProps = AuthProviderProps;
30
35
  *
31
36
  * @public
32
37
  */
33
- export function HerculesAuthProvider(props: HerculesAuthProviderProps) {
34
- return <ReactAuthProvider {...DEFAULT_AUTH_CONFIG} {...props} />;
38
+ export function HerculesAuthProvider({
39
+ children,
40
+ userManagerSettings,
41
+ ...props
42
+ }: HerculesAuthProviderProps) {
43
+ const [userManager] = useState(
44
+ () =>
45
+ new UserManager({
46
+ ...userManagerSettings,
47
+ authority: userManagerSettings.authority,
48
+ client_id: userManagerSettings.client_id,
49
+ prompt: userManagerSettings.prompt ?? "select_account",
50
+ response_type: userManagerSettings.response_type ?? "code",
51
+ scope:
52
+ userManagerSettings.scope ?? "openid profile email offline_access",
53
+ redirect_uri:
54
+ userManagerSettings.redirect_uri ??
55
+ `${window.location.origin}/auth/callback`,
56
+ post_logout_redirect_uri:
57
+ userManagerSettings.post_logout_redirect_uri ??
58
+ window.location.origin,
59
+ userStore:
60
+ userManagerSettings.userStore ??
61
+ new WebStorageStateStore({ store: window.localStorage }),
62
+
63
+ }),
64
+ );
65
+
66
+ return (
67
+ <ReactAuthProvider
68
+ userManager={userManager}
69
+ {...DEFAULT_AUTH_CONFIG}
70
+ {...props}
71
+ >
72
+ {children}
73
+ </ReactAuthProvider>
74
+ );
35
75
  }
@@ -1,3 +1,9 @@
1
1
  export * from "./HerculesAuthProvider";
2
- export * from "./use-auth";
3
2
  export * from "./use-user";
3
+
4
+ // rexports of react-oidc-context
5
+ export {
6
+ useAuth,
7
+ type AuthContextProps,
8
+ hasAuthParams,
9
+ } from "react-oidc-context";
@@ -1,4 +0,0 @@
1
- "use client";
2
-
3
- import { useAuth } from "react-oidc-context";
4
- export { useAuth };