@usehercules/auth 1.0.26 → 1.0.28

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 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-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/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"]}
@@ -1,11 +1,16 @@
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 = Omit<AuthProviderUserManagerProps, "userManager"> & {
9
+ userManagerSettings?: Partial<UserManagerSettings>;
10
+ authority: string;
11
+ client_id: string;
12
+ };
13
+ declare function HerculesAuthProvider({ children, userManagerSettings, authority, client_id, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
9
14
 
10
15
  declare function useUser(): {
11
16
  id: string | undefined;
@@ -1,11 +1,16 @@
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 = Omit<AuthProviderUserManagerProps, "userManager"> & {
9
+ userManagerSettings?: Partial<UserManagerSettings>;
10
+ authority: string;
11
+ client_id: string;
12
+ };
13
+ declare function HerculesAuthProvider({ children, userManagerSettings, authority, client_id, ...props }: HerculesAuthProviderProps): react_jsx_runtime.JSX.Element;
9
14
 
10
15
  declare function useUser(): {
11
16
  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{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-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/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.26",
3
+ "version": "1.0.28",
4
4
  "description": "Authentication utilities for Hercules applications using OIDC",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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
+ }
@@ -1,9 +1,24 @@
1
1
  "use client";
2
2
 
3
+ import { useState } from "react";
3
4
  import {
4
5
  AuthProvider as ReactAuthProvider,
5
- type AuthProviderProps,
6
+ type AuthProviderUserManagerProps,
6
7
  } from "react-oidc-context";
8
+ import {
9
+ UserManager,
10
+ WebStorageStateStore,
11
+ type UserManagerSettings,
12
+ } from "oidc-client-ts";
13
+
14
+ export type HerculesAuthProviderProps = Omit<
15
+ AuthProviderUserManagerProps,
16
+ "userManager"
17
+ > & {
18
+ userManagerSettings?: Partial<UserManagerSettings>;
19
+ authority: string;
20
+ client_id: string;
21
+ };
7
22
 
8
23
  function onSigninCallback() {
9
24
  window.history.replaceState({}, document.title, window.location.pathname);
@@ -13,23 +28,53 @@ function onSignoutCallback() {
13
28
  window.location.pathname = "";
14
29
  }
15
30
 
16
- 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,
31
+ const DEFAULT_AUTH_CONFIG: Partial<HerculesAuthProviderProps> = {
22
32
  onSignoutCallback,
33
+ onSigninCallback,
23
34
  };
24
35
 
25
- export type HerculesAuthProviderProps = AuthProviderProps;
26
-
27
36
  /**
28
37
  * A wrapper React component which provides a {@link ReactAuthProvider}
29
38
  * configured with Hercules Auth.
30
39
  *
31
40
  * @public
32
41
  */
33
- export function HerculesAuthProvider(props: HerculesAuthProviderProps) {
34
- return <ReactAuthProvider {...DEFAULT_AUTH_CONFIG} {...props} />;
42
+ export function HerculesAuthProvider({
43
+ children,
44
+ userManagerSettings,
45
+ authority,
46
+ client_id,
47
+ ...props
48
+ }: HerculesAuthProviderProps) {
49
+ const [userManager] = useState(
50
+ () =>
51
+ new UserManager({
52
+ ...userManagerSettings,
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",
57
+ scope:
58
+ userManagerSettings?.scope ?? "openid profile email offline_access",
59
+ redirect_uri:
60
+ userManagerSettings?.redirect_uri ??
61
+ `${window.location.origin}/auth/callback`,
62
+ post_logout_redirect_uri:
63
+ userManagerSettings?.post_logout_redirect_uri ??
64
+ window.location.origin,
65
+ userStore:
66
+ userManagerSettings?.userStore ??
67
+ new WebStorageStateStore({ store: window.localStorage }),
68
+ }),
69
+ );
70
+
71
+ return (
72
+ <ReactAuthProvider
73
+ userManager={userManager}
74
+ {...DEFAULT_AUTH_CONFIG}
75
+ {...props}
76
+ >
77
+ {children}
78
+ </ReactAuthProvider>
79
+ );
35
80
  }
@@ -1,3 +1,10 @@
1
+ export * from "./AuthCallbackPage";
1
2
  export * from "./HerculesAuthProvider";
2
- export * from "./use-auth";
3
3
  export * from "./use-user";
4
+
5
+ // rexports of react-oidc-context
6
+ export {
7
+ type AuthContextProps,
8
+ hasAuthParams,
9
+ useAuth,
10
+ } from "react-oidc-context";
@@ -1,4 +0,0 @@
1
- "use client";
2
-
3
- import { useAuth } from "react-oidc-context";
4
- export { useAuth };