@tern-secure/react 1.1.5 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ctx/AuthProvider.d.mts +13 -3
- package/dist/ctx/AuthProvider.d.ts +13 -3
- package/dist/ctx/AuthProvider.js +1 -1
- package/dist/ctx/AuthProvider.js.map +1 -1
- package/dist/ctx/AuthProvider.mjs +1 -1
- package/dist/ctx/AuthProvider.mjs.map +1 -1
- package/dist/ctx/IsomorphicTernSecureCtx.d.mts +5 -5
- package/dist/ctx/IsomorphicTernSecureCtx.d.ts +5 -5
- package/dist/ctx/IsomorphicTernSecureCtx.js +1 -1
- package/dist/ctx/IsomorphicTernSecureCtx.js.map +1 -1
- package/dist/ctx/IsomorphicTernSecureCtx.mjs +1 -1
- package/dist/ctx/IsomorphicTernSecureCtx.mjs.map +1 -1
- package/dist/ctx/TernSecureAuthResourcesCtx.d.mts +6 -0
- package/dist/ctx/TernSecureAuthResourcesCtx.d.ts +6 -0
- package/dist/ctx/TernSecureAuthResourcesCtx.js +2 -0
- package/dist/ctx/TernSecureAuthResourcesCtx.js.map +1 -0
- package/dist/ctx/TernSecureAuthResourcesCtx.mjs +2 -0
- package/dist/ctx/TernSecureAuthResourcesCtx.mjs.map +1 -0
- package/dist/ctx/TernSecureCtxProvider.d.mts +6 -8
- package/dist/ctx/TernSecureCtxProvider.d.ts +6 -8
- package/dist/ctx/TernSecureCtxProvider.js +1 -1
- package/dist/ctx/TernSecureCtxProvider.js.map +1 -1
- package/dist/ctx/TernSecureCtxProvider.mjs +1 -1
- package/dist/ctx/TernSecureCtxProvider.mjs.map +1 -1
- package/dist/ctx/TernSecureProvider.js +1 -1
- package/dist/ctx/TernSecureProvider.js.map +1 -1
- package/dist/ctx/TernSecureProvider.mjs +1 -1
- package/dist/ctx/TernSecureProvider.mjs.map +1 -1
- package/dist/hooks/useAssertWrappedTernSecureProvider.d.mts +2 -2
- package/dist/hooks/useAssertWrappedTernSecureProvider.d.ts +2 -2
- package/dist/hooks/useAssertWrappedTernSecureProvider.js +2 -2
- package/dist/hooks/useAssertWrappedTernSecureProvider.js.map +1 -1
- package/dist/hooks/useAssertWrappedTernSecureProvider.mjs +2 -2
- package/dist/hooks/useAssertWrappedTernSecureProvider.mjs.map +1 -1
- package/dist/hooks/useAuth.d.mts +2 -2
- package/dist/hooks/useAuth.d.ts +2 -2
- package/dist/hooks/useAuth.js +1 -1
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/hooks/useAuth.mjs +1 -1
- package/dist/hooks/useAuth.mjs.map +1 -1
- package/dist/hooks/useIdToken.js +1 -1
- package/dist/hooks/useIdToken.js.map +1 -1
- package/dist/hooks/useIdToken.mjs +1 -1
- package/dist/hooks/useIdToken.mjs.map +1 -1
- package/dist/hooks/useSession.js +1 -1
- package/dist/hooks/useSession.js.map +1 -1
- package/dist/hooks/useSession.mjs +1 -1
- package/dist/hooks/useSession.mjs.map +1 -1
- package/dist/hooks/useSignIn.d.mts +17 -0
- package/dist/hooks/useSignIn.d.ts +17 -0
- package/dist/hooks/useSignIn.js +2 -0
- package/dist/hooks/useSignIn.js.map +1 -0
- package/dist/hooks/useSignIn.mjs +2 -0
- package/dist/hooks/useSignIn.mjs.map +1 -0
- package/dist/index.d.mts +2 -7
- package/dist/index.d.ts +2 -7
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/lib/isoTernSecureAuth.d.mts +46 -0
- package/dist/lib/isoTernSecureAuth.d.ts +46 -0
- package/dist/lib/isoTernSecureAuth.js +2 -0
- package/dist/lib/isoTernSecureAuth.js.map +1 -0
- package/dist/lib/isoTernSecureAuth.mjs +2 -0
- package/dist/lib/isoTernSecureAuth.mjs.map +1 -0
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/types.d.mts +16 -6
- package/dist/types.d.ts +16 -6
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/config.js +2 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/config.mjs +3 -3
- package/dist/utils/config.mjs.map +1 -1
- package/dist/utils/construct.js.map +1 -1
- package/dist/utils/construct.mjs +1 -1
- package/dist/utils/construct.mjs.map +1 -1
- package/dist/utils/debug.js +1 -1
- package/dist/utils/debug.js.map +1 -1
- package/dist/utils/debug.mjs +1 -1
- package/dist/utils/debug.mjs.map +1 -1
- package/package.json +6 -5
- package/dist/client/actions.d.mts +0 -2
- package/dist/client/actions.d.ts +0 -2
- package/dist/client/actions.js +0 -2
- package/dist/client/actions.js.map +0 -1
- package/dist/client/actions.mjs +0 -1
- package/dist/client/actions.mjs.map +0 -1
- package/dist/client/session.d.mts +0 -9
- package/dist/client/session.d.ts +0 -9
- package/dist/client/session.js +0 -2
- package/dist/client/session.js.map +0 -1
- package/dist/client/session.mjs +0 -2
- package/dist/client/session.mjs.map +0 -1
- package/dist/components/TernSecureHostRenderer.d.mts +0 -32
- package/dist/components/TernSecureHostRenderer.d.ts +0 -32
- package/dist/components/TernSecureHostRenderer.js +0 -2
- package/dist/components/TernSecureHostRenderer.js.map +0 -1
- package/dist/components/TernSecureHostRenderer.mjs +0 -2
- package/dist/components/TernSecureHostRenderer.mjs.map +0 -1
- package/dist/components/background.d.mts +0 -5
- package/dist/components/background.d.ts +0 -5
- package/dist/components/background.js +0 -2
- package/dist/components/background.js.map +0 -1
- package/dist/components/background.mjs +0 -2
- package/dist/components/background.mjs.map +0 -1
- package/dist/components/old.d.mts +0 -2
- package/dist/components/old.d.ts +0 -2
- package/dist/components/old.js +0 -2
- package/dist/components/old.js.map +0 -1
- package/dist/components/old.mjs +0 -1
- package/dist/components/old.mjs.map +0 -1
- package/dist/components/uiComponent.d.mts +0 -30
- package/dist/components/uiComponent.d.ts +0 -30
- package/dist/components/uiComponent.js +0 -2
- package/dist/components/uiComponent.js.map +0 -1
- package/dist/components/uiComponent.mjs +0 -2
- package/dist/components/uiComponent.mjs.map +0 -1
- package/dist/components/withTernSecure.d.mts +0 -19
- package/dist/components/withTernSecure.d.ts +0 -19
- package/dist/components/withTernSecure.js +0 -2
- package/dist/components/withTernSecure.js.map +0 -1
- package/dist/components/withTernSecure.mjs +0 -2
- package/dist/components/withTernSecure.mjs.map +0 -1
- package/dist/hooks/useAuthState.d.mts +0 -17
- package/dist/hooks/useAuthState.d.ts +0 -17
- package/dist/hooks/useAuthState.js +0 -2
- package/dist/hooks/useAuthState.js.map +0 -1
- package/dist/hooks/useAuthState.mjs +0 -2
- package/dist/hooks/useAuthState.mjs.map +0 -1
- package/dist/hooks/useMaxAllowedInstances.d.mts +0 -6
- package/dist/hooks/useMaxAllowedInstances.d.ts +0 -6
- package/dist/hooks/useMaxAllowedInstances.js +0 -2
- package/dist/hooks/useMaxAllowedInstances.js.map +0 -1
- package/dist/hooks/useMaxAllowedInstances.mjs +0 -2
- package/dist/hooks/useMaxAllowedInstances.mjs.map +0 -1
- package/dist/hooks/useSignUp.d.mts +0 -13
- package/dist/hooks/useSignUp.d.ts +0 -13
- package/dist/hooks/useSignUp.js +0 -2
- package/dist/hooks/useSignUp.js.map +0 -1
- package/dist/hooks/useSignUp.mjs +0 -2
- package/dist/hooks/useSignUp.mjs.map +0 -1
- package/dist/hooks/useWaitForComponentMount.d.mts +0 -8
- package/dist/hooks/useWaitForComponentMount.d.ts +0 -8
- package/dist/hooks/useWaitForComponentMount.js +0 -2
- package/dist/hooks/useWaitForComponentMount.js.map +0 -1
- package/dist/hooks/useWaitForComponentMount.mjs +0 -2
- package/dist/hooks/useWaitForComponentMount.mjs.map +0 -1
- package/dist/lib/isomorphicTernSecure.d.mts +0 -73
- package/dist/lib/isomorphicTernSecure.d.ts +0 -73
- package/dist/lib/isomorphicTernSecure.js +0 -2
- package/dist/lib/isomorphicTernSecure.js.map +0 -1
- package/dist/lib/isomorphicTernSecure.mjs +0 -2
- package/dist/lib/isomorphicTernSecure.mjs.map +0 -1
- package/dist/types/auth.d.mts +0 -2
- package/dist/types/auth.d.ts +0 -2
- package/dist/types/auth.js +0 -2
- package/dist/types/auth.js.map +0 -1
- package/dist/types/auth.mjs +0 -1
- package/dist/types/auth.mjs.map +0 -1
- package/dist/types/client/actions.d.ts +0 -2
- package/dist/types/client/actions.d.ts.map +0 -1
- package/dist/types/client/session.d.ts +0 -7
- package/dist/types/client/session.d.ts.map +0 -1
- package/dist/types/components/TernSecureHostRenderer.d.ts +0 -30
- package/dist/types/components/TernSecureHostRenderer.d.ts.map +0 -1
- package/dist/types/components/background.d.ts +0 -2
- package/dist/types/components/background.d.ts.map +0 -1
- package/dist/types/components/old.d.ts +0 -2
- package/dist/types/components/old.d.ts.map +0 -1
- package/dist/types/components/uiComponent.d.ts +0 -27
- package/dist/types/components/uiComponent.d.ts.map +0 -1
- package/dist/types/components/withTernSecure.d.ts +0 -16
- package/dist/types/components/withTernSecure.d.ts.map +0 -1
- package/dist/types/ctx/AuthProvider.d.ts +0 -3
- package/dist/types/ctx/AuthProvider.d.ts.map +0 -1
- package/dist/types/ctx/IsomorphicTernSecureCtx.d.ts +0 -6
- package/dist/types/ctx/IsomorphicTernSecureCtx.d.ts.map +0 -1
- package/dist/types/ctx/SessionCtx.d.ts +0 -2
- package/dist/types/ctx/SessionCtx.d.ts.map +0 -1
- package/dist/types/ctx/TernSecureCtxProvider.d.ts +0 -14
- package/dist/types/ctx/TernSecureCtxProvider.d.ts.map +0 -1
- package/dist/types/ctx/TernSecureProvider.d.ts +0 -6
- package/dist/types/ctx/TernSecureProvider.d.ts.map +0 -1
- package/dist/types/ctx/UserCtx.d.ts +0 -2
- package/dist/types/ctx/UserCtx.d.ts.map +0 -1
- package/dist/types/hooks/useAssertWrappedTernSecureProvider.d.ts +0 -2
- package/dist/types/hooks/useAssertWrappedTernSecureProvider.d.ts.map +0 -1
- package/dist/types/hooks/useAuth.d.ts +0 -3
- package/dist/types/hooks/useAuth.d.ts.map +0 -1
- package/dist/types/hooks/useAuthState.d.ts +0 -14
- package/dist/types/hooks/useAuthState.d.ts.map +0 -1
- package/dist/types/hooks/useIdToken.d.ts +0 -19
- package/dist/types/hooks/useIdToken.d.ts.map +0 -1
- package/dist/types/hooks/useMaxAllowedInstances.d.ts +0 -4
- package/dist/types/hooks/useMaxAllowedInstances.d.ts.map +0 -1
- package/dist/types/hooks/useSession.d.ts +0 -12
- package/dist/types/hooks/useSession.d.ts.map +0 -1
- package/dist/types/hooks/useSignUp.d.ts +0 -11
- package/dist/types/hooks/useSignUp.d.ts.map +0 -1
- package/dist/types/hooks/useWaitForComponentMount.d.ts +0 -8
- package/dist/types/hooks/useWaitForComponentMount.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -14
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/lib/isomorphicTernSecure.d.ts +0 -70
- package/dist/types/lib/isomorphicTernSecure.d.ts.map +0 -1
- package/dist/types/lib/utils.d.ts +0 -3
- package/dist/types/lib/utils.d.ts.map +0 -1
- package/dist/types/route-handler/internal-route.d.ts +0 -13
- package/dist/types/route-handler/internal-route.d.ts.map +0 -1
- package/dist/types/types/auth.d.ts +0 -2
- package/dist/types/types/auth.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -94
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utils/client-init.d.ts +0 -2
- package/dist/types/utils/client-init.d.ts.map +0 -1
- package/dist/types/utils/config.d.ts +0 -35
- package/dist/types/utils/config.d.ts.map +0 -1
- package/dist/types/utils/construct.d.ts +0 -38
- package/dist/types/utils/construct.d.ts.map +0 -1
- package/dist/types/utils/create-styles.d.ts +0 -99
- package/dist/types/utils/create-styles.d.ts.map +0 -1
- package/dist/types/utils/debug.d.ts +0 -13
- package/dist/types/utils/debug.d.ts.map +0 -1
- package/dist/types/utils/redirect.d.ts +0 -9
- package/dist/types/utils/redirect.d.ts.map +0 -1
- package/dist/utils/client-init.d.mts +0 -2
- package/dist/utils/client-init.d.ts +0 -2
- package/dist/utils/client-init.js +0 -2
- package/dist/utils/client-init.js.map +0 -1
- package/dist/utils/client-init.mjs +0 -1
- package/dist/utils/client-init.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useIdToken.ts"],"sourcesContent":["'use client'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useIdToken.ts"],"sourcesContent":["'use client'\n\nimport type { TernSecureUser } from '@tern-secure/types'\nimport { useCallback, useEffect,useState } from 'react'\n\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider'\nimport { useAuth } from './useAuth'\n\ninterface IdTokenResult {\n token: string | null\n claims: { [key: string]: any } | null\n issuedAtTime: string | null\n expirationTime: string | null\n authTime: string | null\n signInProvider: string | null\n}\n\ninterface IdTokenState {\n tokenResult: IdTokenResult | null\n loading: boolean\n error: Error | null\n}\n\nexport function useIdTokenInternal() {\n //const ternSecureAuthCtx = useAuthProviderCtx()\n useAssertWrappedByTernSecureAuthProvider('useIdToken')\n //const instance = ternSecureAuthCtx\n\n const { isLoaded, user } = useAuth()\n\n const [tokenState, setTokenState] = useState<IdTokenState>({\n tokenResult: null,\n loading: true,\n error: null\n })\n\n const getFormattedTokenResult = useCallback(\n async (user: TernSecureUser): Promise<IdTokenResult> => {\n const result = await user.getIdTokenResult()\n return {\n token: result.token,\n claims: result.claims,\n issuedAtTime: result.issuedAtTime,\n expirationTime: result.expirationTime,\n authTime: result.authTime,\n signInProvider: result.signInProvider\n }\n }, [])\n\n const refreshToken = useCallback(async () => {\n if (!user) {\n setTokenState({\n tokenResult: null,\n loading: false,\n error: null\n })\n return\n }\n\n try {\n setTokenState(prev => ({ ...prev, loading: true }))\n const tokenResult = await getFormattedTokenResult(user)\n setTokenState({\n tokenResult,\n loading: false,\n error: null\n })\n } catch (error) {\n console.error('Failed to refresh token:', error)\n setTokenState({\n tokenResult: null,\n loading: false,\n error: error instanceof Error ? error : new Error('Failed to refresh token')\n })\n }\n }, [getFormattedTokenResult, user])\n\n useEffect(() => {\n if (isLoaded) {\n refreshToken()\n }\n }, [isLoaded, refreshToken])\n\n return {\n ...tokenState,\n refreshToken\n }\n}\n\nexport const useIdToken = useIdTokenInternal"],"mappings":"sbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,uBAAAC,IAAA,eAAAC,EAAAJ,GAGA,IAAAK,EAAgD,iBAEhDC,EAAyD,gDACzDC,EAAwB,qBAiBjB,SAASJ,GAAqB,IAEnC,4CAAyC,YAAY,EAGrD,KAAM,CAAE,SAAAK,EAAU,KAAAC,CAAK,KAAI,WAAQ,EAE7B,CAACC,EAAYC,CAAa,KAAI,YAAuB,CACzD,YAAa,KACb,QAAS,GACT,MAAO,IACT,CAAC,EAEKC,KAA0B,eAC9B,MAAOH,GAAiD,CACxD,MAAMI,EAAS,MAAMJ,EAAK,iBAAiB,EAC3C,MAAO,CACL,MAAOI,EAAO,MACd,OAAQA,EAAO,OACf,aAAcA,EAAO,aACrB,eAAgBA,EAAO,eACvB,SAAUA,EAAO,SACjB,eAAgBA,EAAO,cACzB,CACF,EAAG,CAAC,CAAC,EAECC,KAAe,eAAY,SAAY,CAC3C,GAAI,CAACL,EAAM,CACTE,EAAc,CACZ,YAAa,KACb,QAAS,GACT,MAAO,IACT,CAAC,EACD,MACF,CAEA,GAAI,CACFA,EAAcI,IAAS,CAAE,GAAGA,EAAM,QAAS,EAAK,EAAE,EAClD,MAAMC,EAAc,MAAMJ,EAAwBH,CAAI,EACtDE,EAAc,CACZ,YAAAK,EACA,QAAS,GACT,MAAO,IACT,CAAC,CACH,OAASC,EAAO,CACd,QAAQ,MAAM,2BAA4BA,CAAK,EAC/CN,EAAc,CACZ,YAAa,KACb,QAAS,GACT,MAAOM,aAAiB,MAAQA,EAAQ,IAAI,MAAM,yBAAyB,CAC7E,CAAC,CACH,CACF,EAAG,CAACL,EAAyBH,CAAI,CAAC,EAElC,sBAAU,IAAM,CACVD,GACFM,EAAa,CAEjB,EAAG,CAACN,EAAUM,CAAY,CAAC,EAEpB,CACL,GAAGJ,EACH,aAAAI,CACF,CACF,CAEO,MAAMZ,EAAaC","names":["useIdToken_exports","__export","useIdToken","useIdTokenInternal","__toCommonJS","import_react","import_useAssertWrappedTernSecureProvider","import_useAuth","isLoaded","user","tokenState","setTokenState","getFormattedTokenResult","result","refreshToken","prev","tokenResult","error"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useCallback as i,useEffect as a,useState as d}from"react";import{useAssertWrappedByTernSecureAuthProvider as c}from"./useAssertWrappedTernSecureProvider";import{useAuth as k}from"./useAuth";function T(){c("useIdToken");const{isLoaded:s,user:n}=k(),[u,t]=d({tokenResult:null,loading:!0,error:null}),l=i(async r=>{const e=await r.getIdTokenResult();return{token:e.token,claims:e.claims,issuedAtTime:e.issuedAtTime,expirationTime:e.expirationTime,authTime:e.authTime,signInProvider:e.signInProvider}},[]),o=i(async()=>{if(!n){t({tokenResult:null,loading:!1,error:null});return}try{t(e=>({...e,loading:!0}));const r=await l(n);t({tokenResult:r,loading:!1,error:null})}catch(r){console.error("Failed to refresh token:",r),t({tokenResult:null,loading:!1,error:r instanceof Error?r:new Error("Failed to refresh token")})}},[l,n]);return a(()=>{s&&o()},[s,o]),{...u,refreshToken:o}}const p=T;export{p as useIdToken,T as useIdTokenInternal};
|
|
2
2
|
//# sourceMappingURL=useIdToken.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useIdToken.ts"],"sourcesContent":["'use client'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useIdToken.ts"],"sourcesContent":["'use client'\n\nimport type { TernSecureUser } from '@tern-secure/types'\nimport { useCallback, useEffect,useState } from 'react'\n\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider'\nimport { useAuth } from './useAuth'\n\ninterface IdTokenResult {\n token: string | null\n claims: { [key: string]: any } | null\n issuedAtTime: string | null\n expirationTime: string | null\n authTime: string | null\n signInProvider: string | null\n}\n\ninterface IdTokenState {\n tokenResult: IdTokenResult | null\n loading: boolean\n error: Error | null\n}\n\nexport function useIdTokenInternal() {\n //const ternSecureAuthCtx = useAuthProviderCtx()\n useAssertWrappedByTernSecureAuthProvider('useIdToken')\n //const instance = ternSecureAuthCtx\n\n const { isLoaded, user } = useAuth()\n\n const [tokenState, setTokenState] = useState<IdTokenState>({\n tokenResult: null,\n loading: true,\n error: null\n })\n\n const getFormattedTokenResult = useCallback(\n async (user: TernSecureUser): Promise<IdTokenResult> => {\n const result = await user.getIdTokenResult()\n return {\n token: result.token,\n claims: result.claims,\n issuedAtTime: result.issuedAtTime,\n expirationTime: result.expirationTime,\n authTime: result.authTime,\n signInProvider: result.signInProvider\n }\n }, [])\n\n const refreshToken = useCallback(async () => {\n if (!user) {\n setTokenState({\n tokenResult: null,\n loading: false,\n error: null\n })\n return\n }\n\n try {\n setTokenState(prev => ({ ...prev, loading: true }))\n const tokenResult = await getFormattedTokenResult(user)\n setTokenState({\n tokenResult,\n loading: false,\n error: null\n })\n } catch (error) {\n console.error('Failed to refresh token:', error)\n setTokenState({\n tokenResult: null,\n loading: false,\n error: error instanceof Error ? error : new Error('Failed to refresh token')\n })\n }\n }, [getFormattedTokenResult, user])\n\n useEffect(() => {\n if (isLoaded) {\n refreshToken()\n }\n }, [isLoaded, refreshToken])\n\n return {\n ...tokenState,\n refreshToken\n }\n}\n\nexport const useIdToken = useIdTokenInternal"],"mappings":"aAGA,OAAS,eAAAA,EAAa,aAAAC,EAAU,YAAAC,MAAgB,QAEhD,OAAS,4CAAAC,MAAgD,uCACzD,OAAS,WAAAC,MAAe,YAiBjB,SAASC,GAAqB,CAEnCF,EAAyC,YAAY,EAGrD,KAAM,CAAE,SAAAG,EAAU,KAAAC,CAAK,EAAIH,EAAQ,EAE7B,CAACI,EAAYC,CAAa,EAAIP,EAAuB,CACzD,YAAa,KACb,QAAS,GACT,MAAO,IACT,CAAC,EAEKQ,EAA0BV,EAC9B,MAAOO,GAAiD,CACxD,MAAMI,EAAS,MAAMJ,EAAK,iBAAiB,EAC3C,MAAO,CACL,MAAOI,EAAO,MACd,OAAQA,EAAO,OACf,aAAcA,EAAO,aACrB,eAAgBA,EAAO,eACvB,SAAUA,EAAO,SACjB,eAAgBA,EAAO,cACzB,CACF,EAAG,CAAC,CAAC,EAECC,EAAeZ,EAAY,SAAY,CAC3C,GAAI,CAACO,EAAM,CACTE,EAAc,CACZ,YAAa,KACb,QAAS,GACT,MAAO,IACT,CAAC,EACD,MACF,CAEA,GAAI,CACFA,EAAcI,IAAS,CAAE,GAAGA,EAAM,QAAS,EAAK,EAAE,EAClD,MAAMC,EAAc,MAAMJ,EAAwBH,CAAI,EACtDE,EAAc,CACZ,YAAAK,EACA,QAAS,GACT,MAAO,IACT,CAAC,CACH,OAASC,EAAO,CACd,QAAQ,MAAM,2BAA4BA,CAAK,EAC/CN,EAAc,CACZ,YAAa,KACb,QAAS,GACT,MAAOM,aAAiB,MAAQA,EAAQ,IAAI,MAAM,yBAAyB,CAC7E,CAAC,CACH,CACF,EAAG,CAACL,EAAyBH,CAAI,CAAC,EAElC,OAAAN,EAAU,IAAM,CACVK,GACFM,EAAa,CAEjB,EAAG,CAACN,EAAUM,CAAY,CAAC,EAEpB,CACL,GAAGJ,EACH,aAAAI,CACF,CACF,CAEO,MAAMI,EAAaX","names":["useCallback","useEffect","useState","useAssertWrappedByTernSecureAuthProvider","useAuth","useIdTokenInternal","isLoaded","user","tokenState","setTokenState","getFormattedTokenResult","result","refreshToken","prev","tokenResult","error","useIdToken"]}
|
package/dist/hooks/useSession.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var f=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var h=(n,e)=>{for(var o in e)f(n,o,{get:e[o],enumerable:!0})},L=(n,e,o,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of S(e))!k.call(n,t)&&t!==o&&f(n,t,{get:()=>e[t],enumerable:!(u=g(e,t))||u.enumerable});return n};var v=n=>L(f({},"__esModule",{value:!0}),n);var D={};h(D,{useSession:()=>w});module.exports=v(D);var p=require("@tern-secure/shared/react"),s=require("react"),m=require("./useAssertWrappedTernSecureProvider"),T=require("./useAuth");function w(){const n=(0,p.useTernSecureAuthCtx)();(0,m.useAssertWrappedByTernSecureAuthProvider)("useSession");const{user:e,token:o}=(0,T.useAuth)(),t=n.currentSession,[r,l]=(0,s.useState)({accessToken:o||null,expirationTime:t?.expirationTime||null,error:null,isLoading:!0}),d=(0,s.useMemo)(()=>r.isLoading?"refreshing":r.accessToken?r.error||r.expirationTime?"expired":"active":"inactive",[r]),a=(0,s.useCallback)(async()=>{try{l(x=>({...x,isLoading:!0}));const i=await e?.getIdToken();if(!i)throw new Error("Failed to get ID token");const c=Date.now()+60*60*1e3;l({accessToken:i,expirationTime:c.toString(),error:null,isLoading:!1})}catch(i){console.error("Failed to refresh session:",i),l(c=>({...c,error:i instanceof Error?i:new Error("An unknown error occurred"),isLoading:!1}))}},[e]);return(0,s.useEffect)(()=>{a();const i=setInterval(()=>{r.expirationTime&&Date.now()<5*60*1e3&&a()},60*1e3);return()=>clearInterval(i)},[a]),{accessToken:r.accessToken,expirationTime:r.expirationTime,error:r.error,isLoading:r.isLoading,status:d,user:e,refresh:a}}0&&(module.exports={useSession});
|
|
2
2
|
//# sourceMappingURL=useSession.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useSession.ts"],"sourcesContent":["'use client'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useSession.ts"],"sourcesContent":["'use client'\n\nimport { \n useTernSecureAuthCtx\n} from '@tern-secure/shared/react'\nimport { \n useCallback,\n useEffect,\n useMemo, \n useState} from 'react'\n\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider'\nimport { useAuth } from './useAuth'\n\ninterface SessionData {\n accessToken: string | null\n expirationTime: string | null\n error: Error | null\n isLoading: boolean\n}\n\ntype SessionStatus = 'active' | 'expired' | 'refreshing' | 'inactive'\n\nexport function useSession() {\n const instanceCtx = useTernSecureAuthCtx()\n\n useAssertWrappedByTernSecureAuthProvider('useSession')\n \n const { user, token } = useAuth()\n const instance = instanceCtx\n const session = instance.currentSession\n\n const [sessionData, setSessionData] = useState<SessionData>({\n accessToken: token || null,\n expirationTime: session?.expirationTime|| null, \n error: null,\n isLoading: true\n })\n\n const status = useMemo((): SessionStatus => {\n if (sessionData.isLoading) return 'refreshing'\n if (!sessionData.accessToken) return 'inactive'\n if (sessionData.error) return 'expired'\n if (sessionData.expirationTime) return 'expired'\n return 'active'\n }, [sessionData])\n\n const refreshSession = useCallback(async () => {\n try {\n setSessionData(prev => ({ ...prev, isLoading: true }))\n //if (!isAuthenticated) throw new Error('No authenticated user')\n\n const token = await user?.getIdToken()\n if (!token) throw new Error('Failed to get ID token')\n\n // Set expiration to 1 hour from now (Firebase default)\n const expirationTime = Date.now() + (60 * 60 * 1000)\n\n setSessionData({\n accessToken: token,\n expirationTime: expirationTime.toString(), // Store as string for consistency\n error: null,\n isLoading: false\n \n })\n } catch (error) {\n console.error('Failed to refresh session:', error)\n setSessionData(prev => ({\n ...prev,\n error: error instanceof Error ? error : new Error('An unknown error occurred'),\n isLoading: false\n }))\n }\n }, [ user])\n\n useEffect(() => {\n refreshSession()\n\n // Set up a timer to refresh the token before it expires\n const timer = setInterval(() => {\n if (sessionData.expirationTime) {\n const timeUntilExpiry = Date.now()\n if (timeUntilExpiry < 5 * 60 * 1000) { // Refresh 5 minutes before expiry\n refreshSession()\n }\n }\n }, 60 * 1000) // Check every minute\n\n return () => clearInterval(timer)\n }, [refreshSession])\n\n return {\n accessToken: sessionData.accessToken,\n expirationTime: sessionData.expirationTime,\n error: sessionData.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AAK,KAC7BG,EAAe,CAGrB,EAAG,GAAK,GAAI,EAEZ,MAAO,IAAM,cAAcI,CAAK,CAClC,EAAG,CAACJ,CAAc,CAAC,EAEZ,CACL,YAAaH,EAAY,YACzB,eAAgBA,EAAY,eAC5B,MAAOA,EAAY,MACnB,UAAWA,EAAY,UACvB,OAAAE,EACA,KAAAL,EACA,QAASM,CACX,CACF","names":["useSession_exports","__export","useSession","__toCommonJS","import_react","import_useAssertWrappedTernSecureProvider","import_useAuth","instanceCtx","user","token","session","sessionData","setSessionData","status","refreshSession","prev","expirationTime","error","timer"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useTernSecureAuthCtx as f}from"@tern-secure/shared/react";import{useCallback as p,useEffect as m,useMemo as T,useState as d}from"react";import{useAssertWrappedByTernSecureAuthProvider as x}from"./useAssertWrappedTernSecureProvider";import{useAuth as g}from"./useAuth";function w(){const o=f();x("useSession");const{user:s,token:a}=g(),c=o.currentSession,[e,t]=d({accessToken:a||null,expirationTime:c?.expirationTime||null,error:null,isLoading:!0}),u=T(()=>e.isLoading?"refreshing":e.accessToken?e.error||e.expirationTime?"expired":"active":"inactive",[e]),n=p(async()=>{try{t(l=>({...l,isLoading:!0}));const r=await s?.getIdToken();if(!r)throw new Error("Failed to get ID token");const i=Date.now()+60*60*1e3;t({accessToken:r,expirationTime:i.toString(),error:null,isLoading:!1})}catch(r){console.error("Failed to refresh session:",r),t(i=>({...i,error:r instanceof Error?r:new Error("An unknown error occurred"),isLoading:!1}))}},[s]);return m(()=>{n();const r=setInterval(()=>{e.expirationTime&&Date.now()<5*60*1e3&&n()},60*1e3);return()=>clearInterval(r)},[n]),{accessToken:e.accessToken,expirationTime:e.expirationTime,error:e.error,isLoading:e.isLoading,status:u,user:s,refresh:n}}export{w as useSession};
|
|
2
2
|
//# sourceMappingURL=useSession.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useSession.ts"],"sourcesContent":["'use client'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useSession.ts"],"sourcesContent":["'use client'\n\nimport { \n useTernSecureAuthCtx\n} from '@tern-secure/shared/react'\nimport { \n useCallback,\n useEffect,\n useMemo, \n useState} from 'react'\n\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider'\nimport { useAuth } from './useAuth'\n\ninterface SessionData {\n accessToken: string | null\n expirationTime: string | null\n error: Error | null\n isLoading: boolean\n}\n\ntype SessionStatus = 'active' | 'expired' | 'refreshing' | 'inactive'\n\nexport function useSession() {\n const instanceCtx = useTernSecureAuthCtx()\n\n useAssertWrappedByTernSecureAuthProvider('useSession')\n \n const { user, token } = useAuth()\n const instance = instanceCtx\n const session = instance.currentSession\n\n const [sessionData, setSessionData] = useState<SessionData>({\n accessToken: token || null,\n expirationTime: session?.expirationTime|| null, \n error: null,\n isLoading: true\n })\n\n const status = useMemo((): SessionStatus => {\n if (sessionData.isLoading) return 'refreshing'\n if (!sessionData.accessToken) return 'inactive'\n if (sessionData.error) return 'expired'\n if (sessionData.expirationTime) return 'expired'\n return 'active'\n }, [sessionData])\n\n const refreshSession = useCallback(async () => {\n try {\n setSessionData(prev => ({ ...prev, isLoading: true }))\n //if (!isAuthenticated) throw new Error('No authenticated user')\n\n const token = await user?.getIdToken()\n if (!token) throw new Error('Failed to get ID token')\n\n // Set expiration to 1 hour from now (Firebase default)\n const expirationTime = Date.now() + (60 * 60 * 1000)\n\n setSessionData({\n accessToken: token,\n expirationTime: expirationTime.toString(), // Store as string for consistency\n error: null,\n isLoading: false\n \n })\n } catch (error) {\n console.error('Failed to refresh session:', error)\n setSessionData(prev => ({\n ...prev,\n error: error instanceof Error ? error : new Error('An unknown error occurred'),\n isLoading: false\n }))\n }\n }, [ user])\n\n useEffect(() => {\n refreshSession()\n\n // Set up a timer to refresh the token before it expires\n const timer = setInterval(() => {\n if (sessionData.expirationTime) {\n const timeUntilExpiry = Date.now()\n if (timeUntilExpiry < 5 * 60 * 1000) { // Refresh 5 minutes before expiry\n refreshSession()\n }\n }\n }, 60 * 1000) // Check every minute\n\n return () => clearInterval(timer)\n }, [refreshSession])\n\n return {\n accessToken: sessionData.accessToken,\n expirationTime: sessionData.expirationTime,\n error: sessionData.error,\n isLoading: sessionData.isLoading,\n status,\n user,\n refresh: refreshSession\n }\n}"],"mappings":"aAEA,OACE,wBAAAA,MACK,4BACP,OACE,eAAAC,EACA,aAAAC,EACA,WAAAC,EACA,YAAAC,MAAe,QAEjB,OAAS,4CAAAC,MAAgD,uCACzD,OAAS,WAAAC,MAAe,YAWjB,SAASC,GAAa,CAC3B,MAAMC,EAAcR,EAAqB,EAEzCK,EAAyC,YAAY,EAErD,KAAM,CAAE,KAAAI,EAAM,MAAAC,CAAM,EAAIJ,EAAQ,EAE1BK,EADWH,EACQ,eAEnB,CAACI,EAAaC,CAAc,EAAIT,EAAsB,CAC1D,YAAaM,GAAS,KACtB,eAAgBC,GAAS,gBAAiB,KAC1C,MAAO,KACP,UAAW,EACb,CAAC,EAEKG,EAASX,EAAQ,IACjBS,EAAY,UAAkB,aAC7BA,EAAY,YACbA,EAAY,OACZA,EAAY,eAAuB,UAChC,SAH8B,WAIpC,CAACA,CAAW,CAAC,EAEVG,EAAiBd,EAAY,SAAY,CAC7C,GAAI,CACFY,EAAeG,IAAS,CAAE,GAAGA,EAAM,UAAW,EAAK,EAAE,EAGrD,MAAMN,EAAQ,MAAMD,GAAM,WAAW,EACrC,GAAI,CAACC,EAAO,MAAM,IAAI,MAAM,wBAAwB,EAGpD,MAAMO,EAAiB,KAAK,IAAI,EAAK,GAAK,GAAK,IAE/CJ,EAAe,CACb,YAAaH,EACb,eAAgBO,EAAe,SAAS,EACxC,MAAO,KACP,UAAW,EAEb,CAAC,CACH,OAASC,EAAO,CACd,QAAQ,MAAM,6BAA8BA,CAAK,EACjDL,EAAeG,IAAS,CACtB,GAAGA,EACH,MAAOE,aAAiB,MAAQA,EAAQ,IAAI,MAAM,2BAA2B,EAC7E,UAAW,EACb,EAAE,CACJ,CACF,EAAG,CAAET,CAAI,CAAC,EAEV,OAAAP,EAAU,IAAM,CACda,EAAe,EAGf,MAAMI,EAAQ,YAAY,IAAM,CAC1BP,EAAY,gBACW,KAAK,IAAI,EACZ,EAAI,GAAK,KAC7BG,EAAe,CAGrB,EAAG,GAAK,GAAI,EAEZ,MAAO,IAAM,cAAcI,CAAK,CAClC,EAAG,CAACJ,CAAc,CAAC,EAEZ,CACL,YAAaH,EAAY,YACzB,eAAgBA,EAAY,eAC5B,MAAOA,EAAY,MACnB,UAAWA,EAAY,UACvB,OAAAE,EACA,KAAAL,EACA,QAASM,CACX,CACF","names":["useTernSecureAuthCtx","useCallback","useEffect","useMemo","useState","useAssertWrappedByTernSecureAuthProvider","useAuth","useSession","instanceCtx","user","token","session","sessionData","setSessionData","status","refreshSession","prev","expirationTime","error","timer"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UseSignInReturn, SignInFormValuesTree, SignInResponseTree, ResendEmailVerification } from '@tern-secure/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook to access the SignInResource methods from TernSecureAuth
|
|
5
|
+
* Provides type-safe access to all sign-in related functionality
|
|
6
|
+
*/
|
|
7
|
+
declare const useSignIn: () => UseSignInReturn;
|
|
8
|
+
declare const signIn: {
|
|
9
|
+
withEmailAndPassword: (params: SignInFormValuesTree) => Promise<SignInResponseTree>;
|
|
10
|
+
withSocialProvider: (provider: string, options?: {
|
|
11
|
+
mode?: "popup" | "redirect";
|
|
12
|
+
}) => Promise<SignInResponseTree | void>;
|
|
13
|
+
resendEmailVerification: () => Promise<ResendEmailVerification>;
|
|
14
|
+
checkRedirectResult: () => Promise<SignInResponseTree | null>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { signIn, useSignIn };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UseSignInReturn, SignInFormValuesTree, SignInResponseTree, ResendEmailVerification } from '@tern-secure/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook to access the SignInResource methods from TernSecureAuth
|
|
5
|
+
* Provides type-safe access to all sign-in related functionality
|
|
6
|
+
*/
|
|
7
|
+
declare const useSignIn: () => UseSignInReturn;
|
|
8
|
+
declare const signIn: {
|
|
9
|
+
withEmailAndPassword: (params: SignInFormValuesTree) => Promise<SignInResponseTree>;
|
|
10
|
+
withSocialProvider: (provider: string, options?: {
|
|
11
|
+
mode?: "popup" | "redirect";
|
|
12
|
+
}) => Promise<SignInResponseTree | void>;
|
|
13
|
+
resendEmailVerification: () => Promise<ResendEmailVerification>;
|
|
14
|
+
checkRedirectResult: () => Promise<SignInResponseTree | null>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { signIn, useSignIn };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";"use client";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var i in n)o(e,i,{get:n[i],enumerable:!0})},h=(e,n,i,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of d(n))!l.call(e,t)&&t!==i&&o(e,t,{get:()=>n[t],enumerable:!(s=u(n,t))||s.enumerable});return e};var m=e=>h(o({},"__esModule",{value:!0}),e);var S={};c(S,{signIn:()=>I,useSignIn:()=>g});module.exports=m(S);var r=require("../ctx/TernSecureAuthResourcesCtx"),a=require("./useAssertWrappedTernSecureProvider");const g=()=>{(0,a.useAssertWrappedByTernSecureAuthProvider)("useSignIn");const e=(0,r.useAuthSignInCtx)();return e?{isLoaded:!0,signIn:e}:{isLoaded:!1,signIn:void 0}},I={withEmailAndPassword:async e=>{const n=(0,r.useAuthSignInCtx)();if(!n)throw new Error("SignIn methods not available - auth not initialized");return n.withEmailAndPassword(e)},withSocialProvider:async(e,n)=>{const i=(0,r.useAuthSignInCtx)();if(!i)throw new Error("SignIn methods not available - auth not initialized");return i.withSocialProvider(e,n)},resendEmailVerification:async()=>{const e=(0,r.useAuthSignInCtx)();if(!e)throw new Error("SignIn methods not available - auth not initialized");return e.resendEmailVerification()},checkRedirectResult:async()=>{const e=(0,r.useAuthSignInCtx)();if(!e)throw new Error("SignIn methods not available - auth not initialized");return e.checkRedirectResult()}};0&&(module.exports={signIn,useSignIn});
|
|
2
|
+
//# sourceMappingURL=useSignIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useSignIn.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ResendEmailVerification,\n SignInFormValuesTree,\n SignInResponseTree,\n UseSignInReturn,\n} from \"@tern-secure/types\";\n\nimport { useAuthSignInCtx } from \"../ctx/TernSecureAuthResourcesCtx\";\nimport { useAssertWrappedByTernSecureAuthProvider } from \"./useAssertWrappedTernSecureProvider\";\n\n/**\n * Hook to access the SignInResource methods from TernSecureAuth\n * Provides type-safe access to all sign-in related functionality\n */\nexport const useSignIn = (): UseSignInReturn => {\n useAssertWrappedByTernSecureAuthProvider(\"useSignIn\");\n const auth = useAuthSignInCtx();\n\n if (!auth) {\n return {\n isLoaded: false,\n signIn: undefined,\n };\n }\n\n return {\n isLoaded: true,\n signIn: auth,\n };\n};\n\nexport const signIn = {\n withEmailAndPassword: async (\n params: SignInFormValuesTree\n ): Promise<SignInResponseTree> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.withEmailAndPassword(params);\n },\n\n withSocialProvider: async (\n provider: string,\n options?: { mode?: \"popup\" | \"redirect\" }\n ): Promise<SignInResponseTree | void> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.withSocialProvider(provider, options);\n },\n\n resendEmailVerification: async (): Promise<ResendEmailVerification> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.resendEmailVerification();\n },\n\n checkRedirectResult: async (): Promise<SignInResponseTree | null> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.checkRedirectResult();\n },\n};\n"],"mappings":"sbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,cAAAC,IAAA,eAAAC,EAAAJ,GASA,IAAAK,EAAiC,6CACjCC,EAAyD,gDAMlD,MAAMH,EAAY,IAAuB,IAC9C,4CAAyC,WAAW,EACpD,MAAMI,KAAO,oBAAiB,EAE9B,OAAKA,EAOE,CACL,SAAU,GACV,OAAQA,CACV,EATS,CACL,SAAU,GACV,OAAQ,MACV,CAOJ,EAEaL,EAAS,CACpB,qBAAsB,MACpBM,GACgC,CAChC,MAAMD,KAAO,oBAAiB,EAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,qBAAqBC,CAAM,CACzC,EAEA,mBAAoB,MAClBC,EACAC,IACuC,CACvC,MAAMH,KAAO,oBAAiB,EAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,mBAAmBE,EAAUC,CAAO,CAClD,EAEA,wBAAyB,SAA8C,CACrE,MAAMH,KAAO,oBAAiB,EAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,wBAAwB,CACtC,EAEA,oBAAqB,SAAgD,CACnE,MAAMA,KAAO,oBAAiB,EAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,oBAAoB,CAClC,CACF","names":["useSignIn_exports","__export","signIn","useSignIn","__toCommonJS","import_TernSecureAuthResourcesCtx","import_useAssertWrappedTernSecureProvider","auth","params","provider","options"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useAuthSignInCtx as n}from"../ctx/TernSecureAuthResourcesCtx";import{useAssertWrappedByTernSecureAuthProvider as t}from"./useAssertWrappedTernSecureProvider";const a=()=>{t("useSignIn");const e=n();return e?{isLoaded:!0,signIn:e}:{isLoaded:!1,signIn:void 0}},u={withEmailAndPassword:async e=>{const i=n();if(!i)throw new Error("SignIn methods not available - auth not initialized");return i.withEmailAndPassword(e)},withSocialProvider:async(e,i)=>{const r=n();if(!r)throw new Error("SignIn methods not available - auth not initialized");return r.withSocialProvider(e,i)},resendEmailVerification:async()=>{const e=n();if(!e)throw new Error("SignIn methods not available - auth not initialized");return e.resendEmailVerification()},checkRedirectResult:async()=>{const e=n();if(!e)throw new Error("SignIn methods not available - auth not initialized");return e.checkRedirectResult()}};export{u as signIn,a as useSignIn};
|
|
2
|
+
//# sourceMappingURL=useSignIn.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useSignIn.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ResendEmailVerification,\n SignInFormValuesTree,\n SignInResponseTree,\n UseSignInReturn,\n} from \"@tern-secure/types\";\n\nimport { useAuthSignInCtx } from \"../ctx/TernSecureAuthResourcesCtx\";\nimport { useAssertWrappedByTernSecureAuthProvider } from \"./useAssertWrappedTernSecureProvider\";\n\n/**\n * Hook to access the SignInResource methods from TernSecureAuth\n * Provides type-safe access to all sign-in related functionality\n */\nexport const useSignIn = (): UseSignInReturn => {\n useAssertWrappedByTernSecureAuthProvider(\"useSignIn\");\n const auth = useAuthSignInCtx();\n\n if (!auth) {\n return {\n isLoaded: false,\n signIn: undefined,\n };\n }\n\n return {\n isLoaded: true,\n signIn: auth,\n };\n};\n\nexport const signIn = {\n withEmailAndPassword: async (\n params: SignInFormValuesTree\n ): Promise<SignInResponseTree> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.withEmailAndPassword(params);\n },\n\n withSocialProvider: async (\n provider: string,\n options?: { mode?: \"popup\" | \"redirect\" }\n ): Promise<SignInResponseTree | void> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.withSocialProvider(provider, options);\n },\n\n resendEmailVerification: async (): Promise<ResendEmailVerification> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.resendEmailVerification();\n },\n\n checkRedirectResult: async (): Promise<SignInResponseTree | null> => {\n const auth = useAuthSignInCtx();\n if (!auth) {\n throw new Error(\"SignIn methods not available - auth not initialized\");\n }\n return auth.checkRedirectResult();\n },\n};\n"],"mappings":"aASA,OAAS,oBAAAA,MAAwB,oCACjC,OAAS,4CAAAC,MAAgD,uCAMlD,MAAMC,EAAY,IAAuB,CAC9CD,EAAyC,WAAW,EACpD,MAAME,EAAOH,EAAiB,EAE9B,OAAKG,EAOE,CACL,SAAU,GACV,OAAQA,CACV,EATS,CACL,SAAU,GACV,OAAQ,MACV,CAOJ,EAEaC,EAAS,CACpB,qBAAsB,MACpBC,GACgC,CAChC,MAAMF,EAAOH,EAAiB,EAC9B,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,qBAAqBE,CAAM,CACzC,EAEA,mBAAoB,MAClBC,EACAC,IACuC,CACvC,MAAMJ,EAAOH,EAAiB,EAC9B,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,mBAAmBG,EAAUC,CAAO,CAClD,EAEA,wBAAyB,SAA8C,CACrE,MAAMJ,EAAOH,EAAiB,EAC9B,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,wBAAwB,CACtC,EAEA,oBAAqB,SAAgD,CACnE,MAAMA,EAAOH,EAAiB,EAC9B,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,oBAAoB,CAClC,CACF","names":["useAuthSignInCtx","useAssertWrappedByTernSecureAuthProvider","useSignIn","auth","signIn","params","provider","options"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
export { useAuth } from './hooks/useAuth.mjs';
|
|
2
|
-
export { useSignUp } from './hooks/useSignUp.mjs';
|
|
3
2
|
export { useIdToken } from './hooks/useIdToken.mjs';
|
|
4
3
|
export { useSession } from './hooks/useSession.mjs';
|
|
4
|
+
export { signIn, useSignIn } from './hooks/useSignIn.mjs';
|
|
5
5
|
export { TernSecureCtxProvider } from './ctx/TernSecureCtxProvider.mjs';
|
|
6
6
|
export { TernSecureProvider } from './ctx/TernSecureProvider.mjs';
|
|
7
7
|
export { handleInternalRoute, isAuthRoute, isBaseAuthRoute, isInternalRoute } from './route-handler/internal-route.mjs';
|
|
8
|
-
export { SignIn, SignUp, UserButton } from './components/uiComponent.mjs';
|
|
9
|
-
export { AuthBackground } from './components/background.mjs';
|
|
10
8
|
export { cn } from './lib/utils.mjs';
|
|
11
|
-
export { Browser, IsomorphicTernSecureOptions, TernSecureProviderProps
|
|
12
|
-
export { constructScriptAttributes, loadTernUIScript, ternUIgetScriptUrl } from '@tern-secure/shared/loadTernUIScript';
|
|
13
|
-
export { clearSessionCookie, createSessionCookie } from './client/session.mjs';
|
|
9
|
+
export { Browser, IsoTernSecureAuthOptions, IsomorphicTernSecureOptions, TernSecureProviderProps } from './types.mjs';
|
|
14
10
|
import '@tern-secure/types';
|
|
15
11
|
import 'react/jsx-runtime';
|
|
16
12
|
import 'react';
|
|
17
|
-
import './components/withTernSecure.mjs';
|
|
18
13
|
import 'clsx';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
export { useAuth } from './hooks/useAuth.js';
|
|
2
|
-
export { useSignUp } from './hooks/useSignUp.js';
|
|
3
2
|
export { useIdToken } from './hooks/useIdToken.js';
|
|
4
3
|
export { useSession } from './hooks/useSession.js';
|
|
4
|
+
export { signIn, useSignIn } from './hooks/useSignIn.js';
|
|
5
5
|
export { TernSecureCtxProvider } from './ctx/TernSecureCtxProvider.js';
|
|
6
6
|
export { TernSecureProvider } from './ctx/TernSecureProvider.js';
|
|
7
7
|
export { handleInternalRoute, isAuthRoute, isBaseAuthRoute, isInternalRoute } from './route-handler/internal-route.js';
|
|
8
|
-
export { SignIn, SignUp, UserButton } from './components/uiComponent.js';
|
|
9
|
-
export { AuthBackground } from './components/background.js';
|
|
10
8
|
export { cn } from './lib/utils.js';
|
|
11
|
-
export { Browser, IsomorphicTernSecureOptions, TernSecureProviderProps
|
|
12
|
-
export { constructScriptAttributes, loadTernUIScript, ternUIgetScriptUrl } from '@tern-secure/shared/loadTernUIScript';
|
|
13
|
-
export { clearSessionCookie, createSessionCookie } from './client/session.js';
|
|
9
|
+
export { Browser, IsoTernSecureAuthOptions, IsomorphicTernSecureOptions, TernSecureProviderProps } from './types.js';
|
|
14
10
|
import '@tern-secure/types';
|
|
15
11
|
import 'react/jsx-runtime';
|
|
16
12
|
import 'react';
|
|
17
|
-
import './components/withTernSecure.js';
|
|
18
13
|
import 'clsx';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(o,e)=>{for(var n in e)u(o,n,{get:e[n],enumerable:!0})},a=(o,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of h(e))!T.call(o,t)&&t!==n&&u(o,t,{get:()=>e[t],enumerable:!(p=S(e,t))||p.enumerable});return o};var A=o=>a(u({},"__esModule",{value:!0}),o);var P={};d(P,{TernSecureCtxProvider:()=>f.TernSecureCtxProvider,TernSecureProvider:()=>c.TernSecureProvider,cn:()=>I.cn,handleInternalRoute:()=>r.handleInternalRoute,isAuthRoute:()=>r.isAuthRoute,isBaseAuthRoute:()=>r.isBaseAuthRoute,isInternalRoute:()=>r.isInternalRoute,signIn:()=>s.signIn,useAuth:()=>i.useAuth,useIdToken:()=>m.useIdToken,useSession:()=>x.useSession,useSignIn:()=>s.useSignIn});module.exports=A(P);var i=require("./hooks/useAuth"),m=require("./hooks/useIdToken"),x=require("./hooks/useSession"),s=require("./hooks/useSignIn"),f=require("./ctx/TernSecureCtxProvider"),c=require("./ctx/TernSecureProvider"),r=require("./route-handler/internal-route"),I=require("./lib/utils");0&&(module.exports={TernSecureCtxProvider,TernSecureProvider,cn,handleInternalRoute,isAuthRoute,isBaseAuthRoute,isInternalRoute,signIn,useAuth,useIdToken,useSession,useSignIn});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { useAuth } from \"./hooks/useAuth\"\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { useAuth } from \"./hooks/useAuth\"\nexport { useIdToken } from \"./hooks/useIdToken\"\nexport { useSession } from \"./hooks/useSession\"\nexport { useSignIn, signIn } from \"./hooks/useSignIn\"\nexport {\n TernSecureCtxProvider\n} from './ctx/TernSecureCtxProvider'\nexport {\n TernSecureProvider\n} from './ctx/TernSecureProvider'\n\nexport {\n isAuthRoute,\n isBaseAuthRoute,\n isInternalRoute,\n handleInternalRoute\n} from './route-handler/internal-route'\n\nexport {\n cn\n} from './lib/utils'\n\nexport type {\n IsomorphicTernSecureOptions,\n IsoTernSecureAuthOptions,\n Browser,\n TernSecureProviderProps,\n} from './types'\n\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gZAAAE,EAAAF,GAAA,IAAAG,EAAwB,2BACxBC,EAA2B,8BAC3BC,EAA2B,8BAC3BC,EAAkC,6BAClCC,EAEO,uCACPC,EAEO,oCAEPC,EAKO,0CAEPC,EAEO","names":["index_exports","__export","__toCommonJS","import_useAuth","import_useIdToken","import_useSession","import_useSignIn","import_TernSecureCtxProvider","import_TernSecureProvider","import_internal_route","import_utils"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useAuth as o}from"./hooks/useAuth";import{
|
|
1
|
+
import{useAuth as o}from"./hooks/useAuth";import{useIdToken as n}from"./hooks/useIdToken";import{useSession as u}from"./hooks/useSession";import{useSignIn as i,signIn as m}from"./hooks/useSignIn";import{TernSecureCtxProvider as f}from"./ctx/TernSecureCtxProvider";import{TernSecureProvider as I}from"./ctx/TernSecureProvider";import{isAuthRoute as h,isBaseAuthRoute as T,isInternalRoute as d,handleInternalRoute as a}from"./route-handler/internal-route";import{cn as P}from"./lib/utils";export{f as TernSecureCtxProvider,I as TernSecureProvider,P as cn,a as handleInternalRoute,h as isAuthRoute,T as isBaseAuthRoute,d as isInternalRoute,m as signIn,o as useAuth,n as useIdToken,u as useSession,i as useSignIn};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { useAuth } from \"./hooks/useAuth\"\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { useAuth } from \"./hooks/useAuth\"\nexport { useIdToken } from \"./hooks/useIdToken\"\nexport { useSession } from \"./hooks/useSession\"\nexport { useSignIn, signIn } from \"./hooks/useSignIn\"\nexport {\n TernSecureCtxProvider\n} from './ctx/TernSecureCtxProvider'\nexport {\n TernSecureProvider\n} from './ctx/TernSecureProvider'\n\nexport {\n isAuthRoute,\n isBaseAuthRoute,\n isInternalRoute,\n handleInternalRoute\n} from './route-handler/internal-route'\n\nexport {\n cn\n} from './lib/utils'\n\nexport type {\n IsomorphicTernSecureOptions,\n IsoTernSecureAuthOptions,\n Browser,\n TernSecureProviderProps,\n} from './types'\n\n"],"mappings":"AAAA,OAAS,WAAAA,MAAe,kBACxB,OAAS,cAAAC,MAAkB,qBAC3B,OAAS,cAAAC,MAAkB,qBAC3B,OAAS,aAAAC,EAAW,UAAAC,MAAc,oBAClC,OACI,yBAAAC,MACG,8BACP,OACI,sBAAAC,MACG,2BAEP,OACI,eAAAC,EACA,mBAAAC,EACA,mBAAAC,EACA,uBAAAC,MACG,iCAEP,OACI,MAAAC,MACG","names":["useAuth","useIdToken","useSession","useSignIn","signIn","TernSecureCtxProvider","TernSecureProvider","isAuthRoute","isBaseAuthRoute","isInternalRoute","handleInternalRoute","cn"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
|
+
import { TernSecureAuth, TernSecureAuthStatus, SignInResource, SignUpResource, ListenerCallback, UnsubscribeCallback, SignOutOptions, SignedInSession } from '@tern-secure/types';
|
|
3
|
+
import { IsoTernSecureAuthOptions } from '../types.mjs';
|
|
4
|
+
|
|
5
|
+
declare function inBrowser(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* IsomorphicTernSecure class manages the auth state and UI rendering
|
|
8
|
+
* in both browser and server environments, acting as a proxy for TernSecureAuth
|
|
9
|
+
*/
|
|
10
|
+
declare class IsoTernSecureAuth implements TernSecureAuth {
|
|
11
|
+
#private;
|
|
12
|
+
private readonly _mode;
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly TernSecureAuth;
|
|
15
|
+
private ternauth;
|
|
16
|
+
private preAddListener;
|
|
17
|
+
get status(): TernSecureAuthStatus;
|
|
18
|
+
get isReady(): boolean;
|
|
19
|
+
get isLoading(): boolean;
|
|
20
|
+
get requiresVerification(): boolean;
|
|
21
|
+
get signIn(): SignInResource | undefined | null;
|
|
22
|
+
get signUp(): SignUpResource | undefined | null;
|
|
23
|
+
get user(): _tern_secure_types.TernSecureUser | null | undefined;
|
|
24
|
+
static getOrCreateInstance(options: IsoTernSecureAuthOptions): IsoTernSecureAuth;
|
|
25
|
+
static clearInstances(): void;
|
|
26
|
+
static clearInstance(): void;
|
|
27
|
+
get domain(): string;
|
|
28
|
+
get proxyUrl(): string;
|
|
29
|
+
get mode(): 'browser' | 'server';
|
|
30
|
+
constructor(options: IsoTernSecureAuthOptions);
|
|
31
|
+
get sdkMetadata(): _tern_secure_types.TernAuthSDK | undefined;
|
|
32
|
+
get version(): string | undefined;
|
|
33
|
+
get instanceType(): _tern_secure_types.InstanceType | undefined;
|
|
34
|
+
get apiUrl(): string;
|
|
35
|
+
initTernSecureAuth(): Promise<void>;
|
|
36
|
+
private loadTernSecureAuth;
|
|
37
|
+
on: TernSecureAuth['on'];
|
|
38
|
+
off: TernSecureAuth['off'];
|
|
39
|
+
addListener: (listener: ListenerCallback) => UnsubscribeCallback;
|
|
40
|
+
signOut: (options?: SignOutOptions) => Promise<void>;
|
|
41
|
+
get currentSession(): SignedInSession | null;
|
|
42
|
+
onAuthStateChanged(callback: (user: any) => void): () => void;
|
|
43
|
+
initialize: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { IsoTernSecureAuth, inBrowser };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
|
+
import { TernSecureAuth, TernSecureAuthStatus, SignInResource, SignUpResource, ListenerCallback, UnsubscribeCallback, SignOutOptions, SignedInSession } from '@tern-secure/types';
|
|
3
|
+
import { IsoTernSecureAuthOptions } from '../types.js';
|
|
4
|
+
|
|
5
|
+
declare function inBrowser(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* IsomorphicTernSecure class manages the auth state and UI rendering
|
|
8
|
+
* in both browser and server environments, acting as a proxy for TernSecureAuth
|
|
9
|
+
*/
|
|
10
|
+
declare class IsoTernSecureAuth implements TernSecureAuth {
|
|
11
|
+
#private;
|
|
12
|
+
private readonly _mode;
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly TernSecureAuth;
|
|
15
|
+
private ternauth;
|
|
16
|
+
private preAddListener;
|
|
17
|
+
get status(): TernSecureAuthStatus;
|
|
18
|
+
get isReady(): boolean;
|
|
19
|
+
get isLoading(): boolean;
|
|
20
|
+
get requiresVerification(): boolean;
|
|
21
|
+
get signIn(): SignInResource | undefined | null;
|
|
22
|
+
get signUp(): SignUpResource | undefined | null;
|
|
23
|
+
get user(): _tern_secure_types.TernSecureUser | null | undefined;
|
|
24
|
+
static getOrCreateInstance(options: IsoTernSecureAuthOptions): IsoTernSecureAuth;
|
|
25
|
+
static clearInstances(): void;
|
|
26
|
+
static clearInstance(): void;
|
|
27
|
+
get domain(): string;
|
|
28
|
+
get proxyUrl(): string;
|
|
29
|
+
get mode(): 'browser' | 'server';
|
|
30
|
+
constructor(options: IsoTernSecureAuthOptions);
|
|
31
|
+
get sdkMetadata(): _tern_secure_types.TernAuthSDK | undefined;
|
|
32
|
+
get version(): string | undefined;
|
|
33
|
+
get instanceType(): _tern_secure_types.InstanceType | undefined;
|
|
34
|
+
get apiUrl(): string;
|
|
35
|
+
initTernSecureAuth(): Promise<void>;
|
|
36
|
+
private loadTernSecureAuth;
|
|
37
|
+
on: TernSecureAuth['on'];
|
|
38
|
+
off: TernSecureAuth['off'];
|
|
39
|
+
addListener: (listener: ListenerCallback) => UnsubscribeCallback;
|
|
40
|
+
signOut: (options?: SignOutOptions) => Promise<void>;
|
|
41
|
+
get currentSession(): SignedInSession | null;
|
|
42
|
+
onAuthStateChanged(callback: (user: any) => void): () => void;
|
|
43
|
+
initialize: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { IsoTernSecureAuth, inBrowser };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},S=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of l(e))!p.call(r,i)&&i!==t&&u(r,i,{get:()=>e[i],enumerable:!(n=d(e,i))||n.enumerable});return r};var A=r=>S(u({},"__esModule",{value:!0}),r);var g={};f(g,{IsoTernSecureAuth:()=>h,inBrowser:()=>a});module.exports=A(g);var c=require("@tern-secure/auth"),s=require("@tern-secure/shared/ternStatusEvent"),o=require("@tern-secure/shared/utils");const T={name:"@tern-secure/react",version:"1.1.5",environment:process.env.NODE_ENV};function a(){return typeof window<"u"}class h{_mode;options;TernSecureAuth;ternauth=null;preAddListener=new Map;#i="loading";#s;#t;#n;#r=(0,s.createTernAuthEventBus)();static#e;get status(){return this.ternauth?this.ternauth.status||(this.ternauth.isReady?"ready":"loading"):this.#i}get isReady(){return this.ternauth?.isReady||!1}get isLoading(){return this.ternauth?.isLoading||!1}get requiresVerification(){return this.options.requiresVerification??!0}get signIn(){if(this.ternauth)return this.ternauth.signIn}get signUp(){if(this.ternauth)return this.ternauth.signUp}get user(){if(this.ternauth)return this.ternauth.user}static getOrCreateInstance(e){return(!a()||!this.#e||e.TernSecureAuth&&this.#e.TernSecureAuth!==e.TernSecureAuth)&&(this.#e=new h(e)),this.#e}static clearInstances(){this.#e&&(this.#e.ternauth=null,this.#e=null)}static clearInstance(){this.#e=null}get domain(){if(typeof window<"u"&&window.location)return(0,o.handleValueOrFn)(this.#t,new URL(window.location.href),"");if(typeof this.#t=="function")throw new Error("Unsupported customDomain type: function");return this.#t||""}get proxyUrl(){if(typeof window<"u"&&window.location)return(0,o.handleValueOrFn)(this.#n,new URL(window.location.href),"");if(typeof this.#n=="function")throw new Error("Unsupported customProxyUrl type: function");return this.#n||""}get mode(){return this._mode}constructor(e){const{TernSecureAuth:t=null}=e||{};this.#t=e.ternSecureConfig?.authDomain,this.options={...e},this._mode=a()?"browser":"server",this.#s=this.options.apiUrl,this.TernSecureAuth=t,this.options.sdkMetadata||(this.options.sdkMetadata=T),this.initTernSecureAuth()}get sdkMetadata(){return this.ternauth?.sdkMetadata||this.options.sdkMetadata}get version(){return this.ternauth?.version}get instanceType(){return this.ternauth?.instanceType}get apiUrl(){return this.#s||""}async initTernSecureAuth(){if(this._mode!=="browser"||this.isReady)return;const e=c.TernSecureAuth.initialize(this.options);this.loadTernSecureAuth(e)}loadTernSecureAuth=e=>{if(!e)throw new Error("TernAuth instance is not initialized");return this.ternauth=e,this.preAddListener.forEach((t,n)=>{t.unsubscribe=e.addListener(n)}),this.#r.getListeners("status").forEach(t=>{this.on("status",t,{notify:!0})}),typeof this.ternauth.status>"u"&&(console.log("[IsoTernSecureAuth] TernSecureAuth has no status, setting internal status to ready"),this.#i="ready",this.#r.emit(s.ternEvents.Status,"ready")),this.ternauth};on=(...e)=>this.ternauth?.on?this.ternauth.on(...e):this.#r.on(...e);off=(...e)=>this.ternauth?.off?this.ternauth.off(...e):this.#r.off(...e);addListener=e=>{if(this.ternauth)return this.ternauth.addListener(e);{const t=()=>{const n=this.preAddListener.get(e);n&&(n.unsubscribe(),this.preAddListener.delete(e))};return this.preAddListener.set(e,{unsubscribe:t}),t}};signOut=async e=>{if(!this.ternauth)throw new Error("TernSecureAuth not initialized");await this.ternauth.signOut()};get currentSession(){return this.ternauth?this.ternauth.currentSession:null}onAuthStateChanged(e){return this.ternauth?this.ternauth.onAuthStateChanged(e):(console.warn("[IsoTernSecureAuth] TernAuth not initialized, cannot set up auth state listener"),()=>{})}#u(){return new Promise(e=>{e(this.ternauth)})}initialize=async()=>{try{await this.#u()}catch(e){throw console.error("[IsomorphicTernSecure] Failed to initialize TernSecureAuth:",e),e}}}0&&(module.exports={IsoTernSecureAuth,inBrowser});
|
|
2
|
+
//# sourceMappingURL=isoTernSecureAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/isoTernSecureAuth.ts"],"sourcesContent":["import { TernSecureAuth as TernSecureAuthImpl } from '@tern-secure/auth'\nimport { createTernAuthEventBus, ternEvents } from '@tern-secure/shared/ternStatusEvent';\nimport { handleValueOrFn } from '@tern-secure/shared/utils';\nimport type {\n DomainOrProxyUrl,\n ListenerCallback,\n SignedInSession,\n SignInResource,\n SignOutOptions,\n SignUpResource,\n TernSecureAuth,\n TernSecureAuthStatus,\n UnsubscribeCallback,\n} from '@tern-secure/types';\n\nimport type { IsoTernSecureAuthOptions, TernSecureAuthProps } from '../types';\n\nconst SDK_METADATA = {\n name: __PACKAGE_NAME__,\n version: __PACKAGE_VERSION__,\n environment: process.env.NODE_ENV,\n};\n\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\n/**\n * IsomorphicTernSecure class manages the auth state and UI rendering\n * in both browser and server environments, acting as a proxy for TernSecureAuth\n */\nexport class IsoTernSecureAuth implements TernSecureAuth {\n private readonly _mode: 'browser' | 'server';\n private readonly options: IsoTernSecureAuthOptions;\n private readonly TernSecureAuth: TernSecureAuthProps;\n private ternauth: TernSecureAuthProps | null = null;\n private preAddListener = new Map<ListenerCallback, { unsubscribe: UnsubscribeCallback }>();\n\n #status: TernSecureAuthStatus = 'loading';\n #apiUrl: string | undefined;\n #domain: DomainOrProxyUrl['domain'];\n #proxyUrl: DomainOrProxyUrl['proxyUrl'];\n #eventBus = createTernAuthEventBus();\n\n static #instance: IsoTernSecureAuth | null | undefined;\n\n get status(): TernSecureAuthStatus {\n if (!this.ternauth) {\n return this.#status;\n }\n return this.ternauth.status || (this.ternauth.isReady ? 'ready' : 'loading');\n }\n\n get isReady(): boolean {\n return this.ternauth?.isReady || false;\n }\n\n get isLoading(): boolean {\n return this.ternauth?.isLoading || false;\n }\n\n get requiresVerification(): boolean {\n return this.options.requiresVerification ?? true;\n }\n\n get signIn(): SignInResource | undefined | null {\n if (this.ternauth) {\n return this.ternauth.signIn;\n }\n return undefined;\n }\n\n get signUp(): SignUpResource | undefined | null {\n if (this.ternauth) {\n return this.ternauth.signUp;\n }\n return undefined;\n }\n\n get user() {\n if (this.ternauth) {\n return this.ternauth.user;\n }\n }\n\n static getOrCreateInstance(options: IsoTernSecureAuthOptions) {\n if (\n !inBrowser() ||\n !this.#instance ||\n (options.TernSecureAuth && this.#instance.TernSecureAuth !== options.TernSecureAuth)\n ) {\n this.#instance = new IsoTernSecureAuth(options);\n }\n //console.log('[IsoTernSecureAuth] getOrCreateInstance', this.#instance);\n return this.#instance;\n }\n\n static clearInstances() {\n if (this.#instance) {\n this.#instance.ternauth = null;\n this.#instance = null;\n }\n }\n\n static clearInstance() {\n this.#instance = null;\n }\n\n get domain(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#domain, new URL(window.location.href), '');\n }\n if (typeof this.#domain === 'function') {\n throw new Error('Unsupported customDomain type: function');\n }\n return this.#domain || '';\n }\n\n get proxyUrl(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#proxyUrl, new URL(window.location.href), '');\n }\n if (typeof this.#proxyUrl === 'function') {\n throw new Error('Unsupported customProxyUrl type: function');\n }\n return this.#proxyUrl || '';\n }\n\n get mode(): 'browser' | 'server' {\n return this._mode;\n }\n\n constructor(options: IsoTernSecureAuthOptions) {\n const { TernSecureAuth = null } = options || {};\n this.#domain = options.ternSecureConfig?.authDomain;\n this.options = { ...options };\n this._mode = inBrowser() ? 'browser' : 'server';\n this.#apiUrl = this.options.apiUrl;\n this.TernSecureAuth = TernSecureAuth;\n\n if (!this.options.sdkMetadata) {\n this.options.sdkMetadata = SDK_METADATA;\n }\n\n this.initTernSecureAuth();\n }\n\n get sdkMetadata() {\n return this.ternauth?.sdkMetadata || this.options.sdkMetadata;\n }\n\n get version() {\n return this.ternauth?.version;\n }\n\n get instanceType() {\n return this.ternauth?.instanceType;\n }\n\n get apiUrl() {\n return this.#apiUrl || '';\n }\n\n async initTernSecureAuth() {\n if (this._mode !== 'browser' || this.isReady) {\n return;\n }\n\n const tern = TernSecureAuthImpl.initialize(this.options);\n this.loadTernSecureAuth(tern);\n }\n\n private loadTernSecureAuth = (ternauth: TernSecureAuthProps | undefined) => {\n if (!ternauth) {\n throw new Error('TernAuth instance is not initialized');\n }\n\n this.ternauth = ternauth;\n this.preAddListener.forEach((listenerHandlers, listener) => {\n listenerHandlers.unsubscribe = ternauth.addListener(listener);\n });\n\n this.#eventBus.getListeners('status').forEach(listener => {\n this.on('status', listener, { notify: true });\n });\n\n if (typeof this.ternauth.status === 'undefined') {\n console.log(\n '[IsoTernSecureAuth] TernSecureAuth has no status, setting internal status to ready',\n );\n this.#status = 'ready';\n this.#eventBus.emit(ternEvents.Status, 'ready');\n }\n\n return this.ternauth;\n };\n\n public on: TernSecureAuth['on'] = (...args) => {\n if (this.ternauth?.on) {\n return this.ternauth.on(...args);\n } else {\n return this.#eventBus.on(...args);\n }\n };\n\n public off: TernSecureAuth['off'] = (...args) => {\n if (this.ternauth?.off) {\n return this.ternauth.off(...args);\n } else {\n return this.#eventBus.off(...args);\n }\n };\n\n addListener = (listener: ListenerCallback): UnsubscribeCallback => {\n if (this.ternauth) {\n return this.ternauth.addListener(listener);\n } else {\n const unsubscribe = () => {\n const listenerHandlers = this.preAddListener.get(listener);\n if (listenerHandlers) {\n listenerHandlers.unsubscribe();\n this.preAddListener.delete(listener);\n }\n };\n this.preAddListener.set(listener, { unsubscribe });\n return unsubscribe;\n }\n };\n\n signOut = async (options?: SignOutOptions): Promise<void> => {\n if (!this.ternauth) {\n throw new Error('TernSecureAuth not initialized');\n }\n await this.ternauth.signOut();\n };\n\n get currentSession(): SignedInSession | null {\n if (!this.ternauth) {\n return null;\n }\n return this.ternauth.currentSession;\n };\n\n onAuthStateChanged(callback: (user: any) => void): () => void {\n if (!this.ternauth) {\n console.warn(\n '[IsoTernSecureAuth] TernAuth not initialized, cannot set up auth state listener',\n );\n return () => {};\n }\n return this.ternauth.onAuthStateChanged(callback);\n }\n\n #awaitForTernSecureAuth(): Promise<TernSecureAuthProps> {\n return new Promise<TernSecureAuthProps>(resolve => {\n resolve(this.ternauth);\n });\n }\n\n initialize = async (): Promise<void> => {\n try {\n await this.#awaitForTernSecureAuth();\n } catch (error) {\n console.error('[IsomorphicTernSecure] Failed to initialize TernSecureAuth:', error);\n throw error;\n }\n };\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CAEAC,IAAwD,CACtD,OAAO,IAAI,QAA6BC,GAAW,CACjDA,EAAQ,KAAK,QAAQ,CACvB,CAAC,CACH,CAEA,WAAa,SAA2B,CACtC,GAAI,CACF,MAAM,KAAKD,GAAwB,CACrC,OAASE,EAAO,CACd,cAAQ,MAAM,8DAA+DA,CAAK,EAC5EA,CACR,CACF,CACF","names":["isoTernSecureAuth_exports","__export","IsoTernSecureAuth","inBrowser","__toCommonJS","import_auth","import_ternStatusEvent","import_utils","SDK_METADATA","#status","#apiUrl","#domain","#proxyUrl","#eventBus","#instance","options","TernSecureAuth","tern","TernSecureAuthImpl","ternauth","listenerHandlers","listener","args","unsubscribe","callback","#awaitForTernSecureAuth","resolve","error"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{TernSecureAuth as u}from"@tern-secure/auth";import{createTernAuthEventBus as o,ternEvents as a}from"@tern-secure/shared/ternStatusEvent";import{handleValueOrFn as n}from"@tern-secure/shared/utils";const h={name:"@tern-secure/react",version:"1.1.5",environment:process.env.NODE_ENV};function i(){return typeof window<"u"}class s{_mode;options;TernSecureAuth;ternauth=null;preAddListener=new Map;#i="loading";#s;#t;#n;#r=o();static#e;get status(){return this.ternauth?this.ternauth.status||(this.ternauth.isReady?"ready":"loading"):this.#i}get isReady(){return this.ternauth?.isReady||!1}get isLoading(){return this.ternauth?.isLoading||!1}get requiresVerification(){return this.options.requiresVerification??!0}get signIn(){if(this.ternauth)return this.ternauth.signIn}get signUp(){if(this.ternauth)return this.ternauth.signUp}get user(){if(this.ternauth)return this.ternauth.user}static getOrCreateInstance(e){return(!i()||!this.#e||e.TernSecureAuth&&this.#e.TernSecureAuth!==e.TernSecureAuth)&&(this.#e=new s(e)),this.#e}static clearInstances(){this.#e&&(this.#e.ternauth=null,this.#e=null)}static clearInstance(){this.#e=null}get domain(){if(typeof window<"u"&&window.location)return n(this.#t,new URL(window.location.href),"");if(typeof this.#t=="function")throw new Error("Unsupported customDomain type: function");return this.#t||""}get proxyUrl(){if(typeof window<"u"&&window.location)return n(this.#n,new URL(window.location.href),"");if(typeof this.#n=="function")throw new Error("Unsupported customProxyUrl type: function");return this.#n||""}get mode(){return this._mode}constructor(e){const{TernSecureAuth:t=null}=e||{};this.#t=e.ternSecureConfig?.authDomain,this.options={...e},this._mode=i()?"browser":"server",this.#s=this.options.apiUrl,this.TernSecureAuth=t,this.options.sdkMetadata||(this.options.sdkMetadata=h),this.initTernSecureAuth()}get sdkMetadata(){return this.ternauth?.sdkMetadata||this.options.sdkMetadata}get version(){return this.ternauth?.version}get instanceType(){return this.ternauth?.instanceType}get apiUrl(){return this.#s||""}async initTernSecureAuth(){if(this._mode!=="browser"||this.isReady)return;const e=u.initialize(this.options);this.loadTernSecureAuth(e)}loadTernSecureAuth=e=>{if(!e)throw new Error("TernAuth instance is not initialized");return this.ternauth=e,this.preAddListener.forEach((t,r)=>{t.unsubscribe=e.addListener(r)}),this.#r.getListeners("status").forEach(t=>{this.on("status",t,{notify:!0})}),typeof this.ternauth.status>"u"&&(console.log("[IsoTernSecureAuth] TernSecureAuth has no status, setting internal status to ready"),this.#i="ready",this.#r.emit(a.Status,"ready")),this.ternauth};on=(...e)=>this.ternauth?.on?this.ternauth.on(...e):this.#r.on(...e);off=(...e)=>this.ternauth?.off?this.ternauth.off(...e):this.#r.off(...e);addListener=e=>{if(this.ternauth)return this.ternauth.addListener(e);{const t=()=>{const r=this.preAddListener.get(e);r&&(r.unsubscribe(),this.preAddListener.delete(e))};return this.preAddListener.set(e,{unsubscribe:t}),t}};signOut=async e=>{if(!this.ternauth)throw new Error("TernSecureAuth not initialized");await this.ternauth.signOut()};get currentSession(){return this.ternauth?this.ternauth.currentSession:null}onAuthStateChanged(e){return this.ternauth?this.ternauth.onAuthStateChanged(e):(console.warn("[IsoTernSecureAuth] TernAuth not initialized, cannot set up auth state listener"),()=>{})}#u(){return new Promise(e=>{e(this.ternauth)})}initialize=async()=>{try{await this.#u()}catch(e){throw console.error("[IsomorphicTernSecure] Failed to initialize TernSecureAuth:",e),e}}}export{s as IsoTernSecureAuth,i as inBrowser};
|
|
2
|
+
//# sourceMappingURL=isoTernSecureAuth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/isoTernSecureAuth.ts"],"sourcesContent":["import { TernSecureAuth as TernSecureAuthImpl } from '@tern-secure/auth'\nimport { createTernAuthEventBus, ternEvents } from '@tern-secure/shared/ternStatusEvent';\nimport { handleValueOrFn } from '@tern-secure/shared/utils';\nimport type {\n DomainOrProxyUrl,\n ListenerCallback,\n SignedInSession,\n SignInResource,\n SignOutOptions,\n SignUpResource,\n TernSecureAuth,\n TernSecureAuthStatus,\n UnsubscribeCallback,\n} from '@tern-secure/types';\n\nimport type { IsoTernSecureAuthOptions, TernSecureAuthProps } from '../types';\n\nconst SDK_METADATA = {\n name: __PACKAGE_NAME__,\n version: __PACKAGE_VERSION__,\n environment: process.env.NODE_ENV,\n};\n\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\n/**\n * IsomorphicTernSecure class manages the auth state and UI rendering\n * in both browser and server environments, acting as a proxy for TernSecureAuth\n */\nexport class IsoTernSecureAuth implements TernSecureAuth {\n private readonly _mode: 'browser' | 'server';\n private readonly options: IsoTernSecureAuthOptions;\n private readonly TernSecureAuth: TernSecureAuthProps;\n private ternauth: TernSecureAuthProps | null = null;\n private preAddListener = new Map<ListenerCallback, { unsubscribe: UnsubscribeCallback }>();\n\n #status: TernSecureAuthStatus = 'loading';\n #apiUrl: string | undefined;\n #domain: DomainOrProxyUrl['domain'];\n #proxyUrl: DomainOrProxyUrl['proxyUrl'];\n #eventBus = createTernAuthEventBus();\n\n static #instance: IsoTernSecureAuth | null | undefined;\n\n get status(): TernSecureAuthStatus {\n if (!this.ternauth) {\n return this.#status;\n }\n return this.ternauth.status || (this.ternauth.isReady ? 'ready' : 'loading');\n }\n\n get isReady(): boolean {\n return this.ternauth?.isReady || false;\n }\n\n get isLoading(): boolean {\n return this.ternauth?.isLoading || false;\n }\n\n get requiresVerification(): boolean {\n return this.options.requiresVerification ?? true;\n }\n\n get signIn(): SignInResource | undefined | null {\n if (this.ternauth) {\n return this.ternauth.signIn;\n }\n return undefined;\n }\n\n get signUp(): SignUpResource | undefined | null {\n if (this.ternauth) {\n return this.ternauth.signUp;\n }\n return undefined;\n }\n\n get user() {\n if (this.ternauth) {\n return this.ternauth.user;\n }\n }\n\n static getOrCreateInstance(options: IsoTernSecureAuthOptions) {\n if (\n !inBrowser() ||\n !this.#instance ||\n (options.TernSecureAuth && this.#instance.TernSecureAuth !== options.TernSecureAuth)\n ) {\n this.#instance = new IsoTernSecureAuth(options);\n }\n //console.log('[IsoTernSecureAuth] getOrCreateInstance', this.#instance);\n return this.#instance;\n }\n\n static clearInstances() {\n if (this.#instance) {\n this.#instance.ternauth = null;\n this.#instance = null;\n }\n }\n\n static clearInstance() {\n this.#instance = null;\n }\n\n get domain(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#domain, new URL(window.location.href), '');\n }\n if (typeof this.#domain === 'function') {\n throw new Error('Unsupported customDomain type: function');\n }\n return this.#domain || '';\n }\n\n get proxyUrl(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#proxyUrl, new URL(window.location.href), '');\n }\n if (typeof this.#proxyUrl === 'function') {\n throw new Error('Unsupported customProxyUrl type: function');\n }\n return this.#proxyUrl || '';\n }\n\n get mode(): 'browser' | 'server' {\n return this._mode;\n }\n\n constructor(options: IsoTernSecureAuthOptions) {\n const { TernSecureAuth = null } = options || {};\n this.#domain = options.ternSecureConfig?.authDomain;\n this.options = { ...options };\n this._mode = inBrowser() ? 'browser' : 'server';\n this.#apiUrl = this.options.apiUrl;\n this.TernSecureAuth = TernSecureAuth;\n\n if (!this.options.sdkMetadata) {\n this.options.sdkMetadata = SDK_METADATA;\n }\n\n this.initTernSecureAuth();\n }\n\n get sdkMetadata() {\n return this.ternauth?.sdkMetadata || this.options.sdkMetadata;\n }\n\n get version() {\n return this.ternauth?.version;\n }\n\n get instanceType() {\n return this.ternauth?.instanceType;\n }\n\n get apiUrl() {\n return this.#apiUrl || '';\n }\n\n async initTernSecureAuth() {\n if (this._mode !== 'browser' || this.isReady) {\n return;\n }\n\n const tern = TernSecureAuthImpl.initialize(this.options);\n this.loadTernSecureAuth(tern);\n }\n\n private loadTernSecureAuth = (ternauth: TernSecureAuthProps | undefined) => {\n if (!ternauth) {\n throw new Error('TernAuth instance is not initialized');\n }\n\n this.ternauth = ternauth;\n this.preAddListener.forEach((listenerHandlers, listener) => {\n listenerHandlers.unsubscribe = ternauth.addListener(listener);\n });\n\n this.#eventBus.getListeners('status').forEach(listener => {\n this.on('status', listener, { notify: true });\n });\n\n if (typeof this.ternauth.status === 'undefined') {\n console.log(\n '[IsoTernSecureAuth] TernSecureAuth has no status, setting internal status to ready',\n );\n this.#status = 'ready';\n this.#eventBus.emit(ternEvents.Status, 'ready');\n }\n\n return this.ternauth;\n };\n\n public on: TernSecureAuth['on'] = (...args) => {\n if (this.ternauth?.on) {\n return this.ternauth.on(...args);\n } else {\n return this.#eventBus.on(...args);\n }\n };\n\n public off: TernSecureAuth['off'] = (...args) => {\n if (this.ternauth?.off) {\n return this.ternauth.off(...args);\n } else {\n return this.#eventBus.off(...args);\n }\n };\n\n addListener = (listener: ListenerCallback): UnsubscribeCallback => {\n if (this.ternauth) {\n return this.ternauth.addListener(listener);\n } else {\n const unsubscribe = () => {\n const listenerHandlers = this.preAddListener.get(listener);\n if (listenerHandlers) {\n listenerHandlers.unsubscribe();\n this.preAddListener.delete(listener);\n }\n };\n this.preAddListener.set(listener, { unsubscribe });\n return unsubscribe;\n }\n };\n\n signOut = async (options?: SignOutOptions): Promise<void> => {\n if (!this.ternauth) {\n throw new Error('TernSecureAuth not initialized');\n }\n await this.ternauth.signOut();\n };\n\n get currentSession(): SignedInSession | null {\n if (!this.ternauth) {\n return null;\n }\n return this.ternauth.currentSession;\n };\n\n onAuthStateChanged(callback: (user: any) => void): () => void {\n if (!this.ternauth) {\n console.warn(\n '[IsoTernSecureAuth] TernAuth not initialized, cannot set up auth state listener',\n );\n return () => {};\n }\n return this.ternauth.onAuthStateChanged(callback);\n }\n\n #awaitForTernSecureAuth(): Promise<TernSecureAuthProps> {\n return new Promise<TernSecureAuthProps>(resolve => {\n resolve(this.ternauth);\n });\n }\n\n initialize = async (): Promise<void> => {\n try {\n await this.#awaitForTernSecureAuth();\n } catch (error) {\n console.error('[IsomorphicTernSecure] Failed to initialize TernSecureAuth:', error);\n throw error;\n }\n };\n}\n"],"mappings":"AAAA,OAAS,kBAAkBA,MAA0B,oBACrD,OAAS,0BAAAC,EAAwB,cAAAC,MAAkB,sCACnD,OAAS,mBAAAC,MAAuB,4BAehC,MAAMC,EAAe,CACnB,KAAM,qBACN,QAAS,QACT,YAAa,QAAQ,IAAI,QAC3B,EAEO,SAASC,GAAqB,CACnC,OAAO,OAAO,OAAW,GAC3B,CAMO,MAAMC,CAA4C,CACtC,MACA,QACA,eACT,SAAuC,KACvC,eAAiB,IAAI,IAE7BC,GAAgC,UAChCC,GACAC,GACAC,GACAC,GAAYV,EAAuB,EAEnC,MAAOW,GAEP,IAAI,QAA+B,CACjC,OAAK,KAAK,SAGH,KAAK,SAAS,SAAW,KAAK,SAAS,QAAU,QAAU,WAFzD,KAAKL,EAGhB,CAEA,IAAI,SAAmB,CACrB,OAAO,KAAK,UAAU,SAAW,EACnC,CAEA,IAAI,WAAqB,CACvB,OAAO,KAAK,UAAU,WAAa,EACrC,CAEA,IAAI,sBAAgC,CAClC,OAAO,KAAK,QAAQ,sBAAwB,EAC9C,CAEA,IAAI,QAA4C,CAC9C,GAAI,KAAK,SACP,OAAO,KAAK,SAAS,MAGzB,CAEA,IAAI,QAA4C,CAC9C,GAAI,KAAK,SACP,OAAO,KAAK,SAAS,MAGzB,CAEA,IAAI,MAAO,CACT,GAAI,KAAK,SACP,OAAO,KAAK,SAAS,IAEzB,CAEA,OAAO,oBAAoBM,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MAAOP,GAA4C,CAC3D,GAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,gCAAgC,EAElD,MAAM,KAAK,SAAS,QAAQ,CAC9B,EAEA,IAAI,gBAAyC,CAC3C,OAAK,KAAK,SAGH,KAAK,SAAS,eAFZ,IAGX,CAEA,mBAAmBQ,EAA2C,CAC5D,OAAK,KAAK,SAMH,KAAK,SAAS,mBAAmBA,CAAQ,GAL9C,QAAQ,KACN,iFACF,EACO,IAAM,CAAC,EAGlB,CAEAC,IAAwD,CACtD,OAAO,IAAI,QAA6BC,GAAW,CACjDA,EAAQ,KAAK,QAAQ,CACvB,CAAC,CACH,CAEA,WAAa,SAA2B,CACtC,GAAI,CACF,MAAM,KAAKD,GAAwB,CACrC,OAASE,EAAO,CACd,cAAQ,MAAM,8DAA+DA,CAAK,EAC5EA,CACR,CACF,CACF","names":["TernSecureAuthImpl","createTernAuthEventBus","ternEvents","handleValueOrFn","SDK_METADATA","inBrowser","IsoTernSecureAuth","#status","#apiUrl","#domain","#proxyUrl","#eventBus","#instance","options","TernSecureAuth","tern","ternauth","listenerHandlers","listener","args","unsubscribe","callback","#awaitForTernSecureAuth","resolve","error"]}
|
package/dist/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["import { type ClassValue,clsx } from \"clsx\"\r\nimport { twMerge } from \"tailwind-merge\"\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n return twMerge(clsx(inputs))\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAqC,gBACrCC,EAAwB,0BAEjB,SAASH,KAAMI,EAAsB,CAC1C,SAAO,cAAQ,QAAKA,CAAM,CAAC,CAC7B","names":["utils_exports","__export","cn","__toCommonJS","import_clsx","import_tailwind_merge","inputs"]}
|
package/dist/lib/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["import { type ClassValue,clsx } from \"clsx\"\r\nimport { twMerge } from \"tailwind-merge\"\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n return twMerge(clsx(inputs))\r\n}\r\n"],"mappings":"AAAA,OAAyB,QAAAA,MAAY,OACrC,OAAS,WAAAC,MAAe,iBAEjB,SAASC,KAAMC,EAAsB,CAC1C,OAAOF,EAAQD,EAAKG,CAAM,CAAC,CAC7B","names":["clsx","twMerge","cn","inputs"]}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { TernSecureInstanceTree,
|
|
1
|
+
import { TernSecureInstanceTree, TernSecureAuthOptions, TernSecureAuth, TernSecureState, TernSecureInstanceTreeOptions, TernSecureConfig } from '@tern-secure/types';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
5
|
apiKey?: string;
|
|
6
|
-
customDomain?: TernSecureInstanceTree[
|
|
7
|
-
proxyUrl?: TernSecureInstanceTree[
|
|
8
|
-
projectId?: TernSecureInstanceTree[
|
|
6
|
+
customDomain?: TernSecureInstanceTree["customDomain"];
|
|
7
|
+
proxyUrl?: TernSecureInstanceTree["proxyUrl"];
|
|
8
|
+
projectId?: TernSecureInstanceTree["projectId"];
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -68,7 +68,7 @@ interface HeadlessUIBrowserConstructor {
|
|
|
68
68
|
* TernSecureProviderProps
|
|
69
69
|
* @param interface
|
|
70
70
|
*/
|
|
71
|
-
type
|
|
71
|
+
type TernSecureProviderPropsOld = IsomorphicTernSecureOptions & {
|
|
72
72
|
children: React.ReactNode;
|
|
73
73
|
initialState?: TernSecureState;
|
|
74
74
|
loadingComponent?: React.ReactNode;
|
|
@@ -92,5 +92,15 @@ type IsomorphicTernSecureOptions = TernSecureInstanceTreeOptions & {
|
|
|
92
92
|
projectId?: string;
|
|
93
93
|
ternSecureConfig?: TernSecureConfig;
|
|
94
94
|
};
|
|
95
|
+
type TernSecureProviderProps = IsoTernSecureAuthOptions & {
|
|
96
|
+
children: React.ReactNode;
|
|
97
|
+
initialState?: TernSecureState;
|
|
98
|
+
loadingComponent?: React.ReactNode;
|
|
99
|
+
bypassApiKey?: boolean;
|
|
100
|
+
};
|
|
101
|
+
type TernSecureAuthProps = TernSecureAuth | undefined | null;
|
|
102
|
+
type IsoTernSecureAuthOptions = TernSecureAuthOptions & {
|
|
103
|
+
TernSecureAuth?: TernSecureAuthProps;
|
|
104
|
+
};
|
|
95
105
|
|
|
96
|
-
export { type AuthError, type Browser, type BrowserConstructor, type ConfigValidationResult, type HeadlessUIBrowser, type HeadlessUIBrowserConstructor, type IsomorphicTernSecureOptions, type SignInResponse, type TernSecureAuthState, type TernSecureProps, type TernSecureProviderProps, type TernSecureUserData, type initialState, isSignInResponse };
|
|
106
|
+
export { type AuthError, type Browser, type BrowserConstructor, type ConfigValidationResult, type HeadlessUIBrowser, type HeadlessUIBrowserConstructor, type IsoTernSecureAuthOptions, type IsomorphicTernSecureOptions, type SignInResponse, type TernSecureAuthProps, type TernSecureAuthState, type TernSecureProps, type TernSecureProviderProps, type TernSecureProviderPropsOld, type TernSecureUserData, type initialState, isSignInResponse };
|