@tern-secure/react 1.2.0-canary.v20251029025859 → 1.2.0-canary.v20251030165007
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/TernSecureCtxProvider.d.mts +2 -2
- package/dist/ctx/TernSecureCtxProvider.d.ts +2 -2
- 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/hooks/useAuth.d.mts +5 -1
- package/dist/hooks/useAuth.d.ts +5 -1
- 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/lib/isoTernSecureAuth.js +1 -1
- package/dist/lib/isoTernSecureAuth.mjs +1 -1
- package/package.json +4 -4
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { TernSecureInitialState, TernSecureResources } from '@tern-secure/types';
|
|
3
3
|
import react__default from 'react';
|
|
4
4
|
import { IsoTernSecureAuthOptions } from '../types.mjs';
|
|
5
5
|
|
|
6
6
|
type TernSecureCtxProviderProps = {
|
|
7
7
|
children: react__default.ReactNode;
|
|
8
8
|
instanceOptions: IsoTernSecureAuthOptions;
|
|
9
|
-
initialState:
|
|
9
|
+
initialState: TernSecureInitialState | undefined;
|
|
10
10
|
};
|
|
11
11
|
type TernSecureCtxProviderState = TernSecureResources;
|
|
12
12
|
declare function TernSecureCtxProvider(props: TernSecureCtxProviderProps): react_jsx_runtime.JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { TernSecureInitialState, TernSecureResources } from '@tern-secure/types';
|
|
3
3
|
import react__default from 'react';
|
|
4
4
|
import { IsoTernSecureAuthOptions } from '../types.js';
|
|
5
5
|
|
|
6
6
|
type TernSecureCtxProviderProps = {
|
|
7
7
|
children: react__default.ReactNode;
|
|
8
8
|
instanceOptions: IsoTernSecureAuthOptions;
|
|
9
|
-
initialState:
|
|
9
|
+
initialState: TernSecureInitialState | undefined;
|
|
10
10
|
};
|
|
11
11
|
type TernSecureCtxProviderState = TernSecureResources;
|
|
12
12
|
declare function TernSecureCtxProvider(props: TernSecureCtxProviderProps): react_jsx_runtime.JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var x=Object.create;var o=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},h=(t,e,n,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of O(e))!E.call(t,s)&&s!==n&&o(t,s,{get:()=>e[s],enumerable:!(u=y(e,s))||u.enumerable});return t};var z=(t,e,n)=>(n=t!=null?x(R(t)):{},h(e||!t||!t.__esModule?o(n,"default",{value:t,enumerable:!0}):n,t)),L=t=>h(o({},"__esModule",{value:!0}),t);var b={};g(b,{TernSecureCtxProvider:()=>M});module.exports=L(b);var c=require("react/jsx-runtime"),T=require("@tern-secure/shared/derivedAuthState"),r=z(require("react")),i=require("../lib/isoTernSecureAuth"),l=require("./AuthProvider"),m=require("./IsomorphicTernSecureCtx");function M(t){const{children:e,initialState:n,instanceOptions:u}=t,{isoTernSecureAuth:s,instanceStatus:a}=N(u),[f,A]=(0,r.useState)({user:s.user,session:s.currentSession});r.default.useEffect(()=>s.addListener(v=>A({...v})),[]);const C=(0,T.deriveAuthState)(f,n),{sessionClaims:S,user:d,userId:p}=C,I=(0,r.useMemo)(()=>({value:{userId:p,user:d,sessionClaims:S}}),[p,d,S]),P=(0,r.useMemo)(()=>({value:s,instanceStatus:a}),[s,a]);return(0,c.jsx)(m.IsoTernSecureAuthCtx.Provider,{value:P,children:(0,c.jsx)(l.AuthProviderCtx.Provider,{value:I,children:e})})}const N=t=>{const e=(0,r.useMemo)(()=>i.IsoTernSecureAuth.getOrCreateInstance(t),[]),[n,u]=(0,r.useState)(e.status);return(0,r.useEffect)(()=>(e.on("status",u),()=>e.off("status",u)),[e]),(0,r.useEffect)(()=>{e.initialize()},[e]),(0,r.useEffect)(()=>()=>{i.IsoTernSecureAuth.clearInstance()},[]),{isoTernSecureAuth:e,instanceStatus:n}};0&&(module.exports={TernSecureCtxProvider});
|
|
2
2
|
//# sourceMappingURL=TernSecureCtxProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ctx/TernSecureCtxProvider.tsx"],"sourcesContent":["'use client';\n\nimport { deriveAuthState } from '@tern-secure/shared/derivedAuthState';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/ctx/TernSecureCtxProvider.tsx"],"sourcesContent":["'use client';\n\nimport { deriveAuthState } from '@tern-secure/shared/derivedAuthState';\nimport type { TernSecureInitialState, TernSecureResources } from '@tern-secure/types';\nimport React, { useEffect, useMemo, useState } from 'react';\n\nimport { IsoTernSecureAuth } from '../lib/isoTernSecureAuth';\nimport type { IsoTernSecureAuthOptions } from '../types';\nimport { AuthProviderCtx } from './AuthProvider';\nimport { IsoTernSecureAuthCtx } from './IsomorphicTernSecureCtx';\n\ntype TernSecureCtxProviderProps = {\n children: React.ReactNode;\n instanceOptions: IsoTernSecureAuthOptions;\n initialState: TernSecureInitialState | undefined;\n};\n\nexport type TernSecureCtxProviderState = TernSecureResources;\n\nexport function TernSecureCtxProvider(props: TernSecureCtxProviderProps) {\n const { children, initialState, instanceOptions } = props;\n\n const { isoTernSecureAuth: instance, instanceStatus } = useInitTernSecureAuth(instanceOptions);\n\n const [authState, setAuthState] = useState<TernSecureCtxProviderState>({\n user: instance.user,\n session: instance.currentSession,\n });\n\n React.useEffect(() => {\n return instance.addListener(e => setAuthState({ ...e }));\n }, []);\n\n const derivedState = deriveAuthState(authState, initialState);\n const { sessionClaims, user, userId } = derivedState;\n\n const authCtx = useMemo(() => {\n const value = {\n userId: userId,\n user: user,\n sessionClaims: sessionClaims,\n };\n return { value };\n }, [userId, user, sessionClaims]);\n\n const ternAuthCtx = useMemo(\n () => ({\n value: instance,\n instanceStatus,\n }),\n [instance, instanceStatus],\n );\n\n return (\n <IsoTernSecureAuthCtx.Provider value={ternAuthCtx}>\n <AuthProviderCtx.Provider value={authCtx}>{children}</AuthProviderCtx.Provider>\n </IsoTernSecureAuthCtx.Provider>\n );\n}\n\nconst useInitTernSecureAuth = (options: IsoTernSecureAuthOptions) => {\n const isoTernSecureAuth = useMemo(() => {\n return IsoTernSecureAuth.getOrCreateInstance(options);\n }, []);\n\n const [instanceStatus, setInstanceStatus] = useState(isoTernSecureAuth.status);\n\n useEffect(() => {\n void isoTernSecureAuth.on('status', setInstanceStatus);\n return () => isoTernSecureAuth.off('status', setInstanceStatus);\n }, [isoTernSecureAuth]);\n\n useEffect(() => {\n void isoTernSecureAuth.initialize();\n }, [isoTernSecureAuth]);\n\n useEffect(() => {\n return () => {\n IsoTernSecureAuth.clearInstance();\n };\n }, []);\n\n return {\n isoTernSecureAuth,\n instanceStatus,\n };\n};\n"],"mappings":"ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAuDM,IAAAI,EAAA,6BArDNC,EAAgC,gDAEhCC,EAAoD,oBAEpDC,EAAkC,oCAElCC,EAAgC,0BAChCC,EAAqC,qCAU9B,SAASP,EAAsBQ,EAAmC,CACvE,KAAM,CAAE,SAAAC,EAAU,aAAAC,EAAc,gBAAAC,CAAgB,EAAIH,EAE9C,CAAE,kBAAmBI,EAAU,eAAAC,CAAe,EAAIC,EAAsBH,CAAe,EAEvF,CAACI,EAAWC,CAAY,KAAI,YAAqC,CACrE,KAAMJ,EAAS,KACf,QAASA,EAAS,cACpB,CAAC,EAED,EAAAK,QAAM,UAAU,IACPL,EAAS,YAAYM,GAAKF,EAAa,CAAE,GAAGE,CAAE,CAAC,CAAC,EACtD,CAAC,CAAC,EAEL,MAAMC,KAAe,mBAAgBJ,EAAWL,CAAY,EACtD,CAAE,cAAAU,EAAe,KAAAC,EAAM,OAAAC,CAAO,EAAIH,EAElCI,KAAU,WAAQ,KAMf,CAAE,MALK,CACZ,OAAQD,EACR,KAAMD,EACN,cAAeD,CACjB,CACe,GACd,CAACE,EAAQD,EAAMD,CAAa,CAAC,EAE1BI,KAAc,WAClB,KAAO,CACL,MAAOZ,EACP,eAAAC,CACF,GACA,CAACD,EAAUC,CAAc,CAC3B,EAEA,SACE,OAAC,uBAAqB,SAArB,CAA8B,MAAOW,EACpC,mBAAC,kBAAgB,SAAhB,CAAyB,MAAOD,EAAU,SAAAd,EAAS,EACtD,CAEJ,CAEA,MAAMK,EAAyBW,GAAsC,CACnE,MAAMC,KAAoB,WAAQ,IACzB,oBAAkB,oBAAoBD,CAAO,EACnD,CAAC,CAAC,EAEC,CAACZ,EAAgBc,CAAiB,KAAI,YAASD,EAAkB,MAAM,EAE7E,sBAAU,KACHA,EAAkB,GAAG,SAAUC,CAAiB,EAC9C,IAAMD,EAAkB,IAAI,SAAUC,CAAiB,GAC7D,CAACD,CAAiB,CAAC,KAEtB,aAAU,IAAM,CACTA,EAAkB,WAAW,CACpC,EAAG,CAACA,CAAiB,CAAC,KAEtB,aAAU,IACD,IAAM,CACX,oBAAkB,cAAc,CAClC,EACC,CAAC,CAAC,EAEE,CACL,kBAAAA,EACA,eAAAb,CACF,CACF","names":["TernSecureCtxProvider_exports","__export","TernSecureCtxProvider","__toCommonJS","import_jsx_runtime","import_derivedAuthState","import_react","import_isoTernSecureAuth","import_AuthProvider","import_IsomorphicTernSecureCtx","props","children","initialState","instanceOptions","instance","instanceStatus","useInitTernSecureAuth","authState","setAuthState","React","e","derivedState","sessionClaims","user","userId","authCtx","ternAuthCtx","options","isoTernSecureAuth","setInstanceStatus"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsx as h}from"react/jsx-runtime";import{deriveAuthState as
|
|
1
|
+
"use client";import{jsx as h}from"react/jsx-runtime";import{deriveAuthState as C}from"@tern-secure/shared/derivedAuthState";import I,{useEffect as u,useMemo as o,useState as p}from"react";import{IsoTernSecureAuth as v}from"../lib/isoTernSecureAuth";import{AuthProviderCtx as P}from"./AuthProvider";import{IsoTernSecureAuthCtx as x}from"./IsomorphicTernSecureCtx";function L(n){const{children:e,initialState:s,instanceOptions:r}=n,{isoTernSecureAuth:t,instanceStatus:i}=y(r),[T,l]=p({user:t.user,session:t.currentSession});I.useEffect(()=>t.addListener(d=>l({...d})),[]);const m=C(T,s),{sessionClaims:c,user:a,userId:S}=m,f=o(()=>({value:{userId:S,user:a,sessionClaims:c}}),[S,a,c]),A=o(()=>({value:t,instanceStatus:i}),[t,i]);return h(x.Provider,{value:A,children:h(P.Provider,{value:f,children:e})})}const y=n=>{const e=o(()=>v.getOrCreateInstance(n),[]),[s,r]=p(e.status);return u(()=>(e.on("status",r),()=>e.off("status",r)),[e]),u(()=>{e.initialize()},[e]),u(()=>()=>{v.clearInstance()},[]),{isoTernSecureAuth:e,instanceStatus:s}};export{L as TernSecureCtxProvider};
|
|
2
2
|
//# sourceMappingURL=TernSecureCtxProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ctx/TernSecureCtxProvider.tsx"],"sourcesContent":["'use client';\n\nimport { deriveAuthState } from '@tern-secure/shared/derivedAuthState';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/ctx/TernSecureCtxProvider.tsx"],"sourcesContent":["'use client';\n\nimport { deriveAuthState } from '@tern-secure/shared/derivedAuthState';\nimport type { TernSecureInitialState, TernSecureResources } from '@tern-secure/types';\nimport React, { useEffect, useMemo, useState } from 'react';\n\nimport { IsoTernSecureAuth } from '../lib/isoTernSecureAuth';\nimport type { IsoTernSecureAuthOptions } from '../types';\nimport { AuthProviderCtx } from './AuthProvider';\nimport { IsoTernSecureAuthCtx } from './IsomorphicTernSecureCtx';\n\ntype TernSecureCtxProviderProps = {\n children: React.ReactNode;\n instanceOptions: IsoTernSecureAuthOptions;\n initialState: TernSecureInitialState | undefined;\n};\n\nexport type TernSecureCtxProviderState = TernSecureResources;\n\nexport function TernSecureCtxProvider(props: TernSecureCtxProviderProps) {\n const { children, initialState, instanceOptions } = props;\n\n const { isoTernSecureAuth: instance, instanceStatus } = useInitTernSecureAuth(instanceOptions);\n\n const [authState, setAuthState] = useState<TernSecureCtxProviderState>({\n user: instance.user,\n session: instance.currentSession,\n });\n\n React.useEffect(() => {\n return instance.addListener(e => setAuthState({ ...e }));\n }, []);\n\n const derivedState = deriveAuthState(authState, initialState);\n const { sessionClaims, user, userId } = derivedState;\n\n const authCtx = useMemo(() => {\n const value = {\n userId: userId,\n user: user,\n sessionClaims: sessionClaims,\n };\n return { value };\n }, [userId, user, sessionClaims]);\n\n const ternAuthCtx = useMemo(\n () => ({\n value: instance,\n instanceStatus,\n }),\n [instance, instanceStatus],\n );\n\n return (\n <IsoTernSecureAuthCtx.Provider value={ternAuthCtx}>\n <AuthProviderCtx.Provider value={authCtx}>{children}</AuthProviderCtx.Provider>\n </IsoTernSecureAuthCtx.Provider>\n );\n}\n\nconst useInitTernSecureAuth = (options: IsoTernSecureAuthOptions) => {\n const isoTernSecureAuth = useMemo(() => {\n return IsoTernSecureAuth.getOrCreateInstance(options);\n }, []);\n\n const [instanceStatus, setInstanceStatus] = useState(isoTernSecureAuth.status);\n\n useEffect(() => {\n void isoTernSecureAuth.on('status', setInstanceStatus);\n return () => isoTernSecureAuth.off('status', setInstanceStatus);\n }, [isoTernSecureAuth]);\n\n useEffect(() => {\n void isoTernSecureAuth.initialize();\n }, [isoTernSecureAuth]);\n\n useEffect(() => {\n return () => {\n IsoTernSecureAuth.clearInstance();\n };\n }, []);\n\n return {\n isoTernSecureAuth,\n instanceStatus,\n };\n};\n"],"mappings":"aAuDM,cAAAA,MAAA,oBArDN,OAAS,mBAAAC,MAAuB,uCAEhC,OAAOC,GAAS,aAAAC,EAAW,WAAAC,EAAS,YAAAC,MAAgB,QAEpD,OAAS,qBAAAC,MAAyB,2BAElC,OAAS,mBAAAC,MAAuB,iBAChC,OAAS,wBAAAC,MAA4B,4BAU9B,SAASC,EAAsBC,EAAmC,CACvE,KAAM,CAAE,SAAAC,EAAU,aAAAC,EAAc,gBAAAC,CAAgB,EAAIH,EAE9C,CAAE,kBAAmBI,EAAU,eAAAC,CAAe,EAAIC,EAAsBH,CAAe,EAEvF,CAACI,EAAWC,CAAY,EAAIb,EAAqC,CACrE,KAAMS,EAAS,KACf,QAASA,EAAS,cACpB,CAAC,EAEDZ,EAAM,UAAU,IACPY,EAAS,YAAYK,GAAKD,EAAa,CAAE,GAAGC,CAAE,CAAC,CAAC,EACtD,CAAC,CAAC,EAEL,MAAMC,EAAenB,EAAgBgB,EAAWL,CAAY,EACtD,CAAE,cAAAS,EAAe,KAAAC,EAAM,OAAAC,CAAO,EAAIH,EAElCI,EAAUpB,EAAQ,KAMf,CAAE,MALK,CACZ,OAAQmB,EACR,KAAMD,EACN,cAAeD,CACjB,CACe,GACd,CAACE,EAAQD,EAAMD,CAAa,CAAC,EAE1BI,EAAcrB,EAClB,KAAO,CACL,MAAOU,EACP,eAAAC,CACF,GACA,CAACD,EAAUC,CAAc,CAC3B,EAEA,OACEf,EAACQ,EAAqB,SAArB,CAA8B,MAAOiB,EACpC,SAAAzB,EAACO,EAAgB,SAAhB,CAAyB,MAAOiB,EAAU,SAAAb,EAAS,EACtD,CAEJ,CAEA,MAAMK,EAAyBU,GAAsC,CACnE,MAAMC,EAAoBvB,EAAQ,IACzBE,EAAkB,oBAAoBoB,CAAO,EACnD,CAAC,CAAC,EAEC,CAACX,EAAgBa,CAAiB,EAAIvB,EAASsB,EAAkB,MAAM,EAE7E,OAAAxB,EAAU,KACHwB,EAAkB,GAAG,SAAUC,CAAiB,EAC9C,IAAMD,EAAkB,IAAI,SAAUC,CAAiB,GAC7D,CAACD,CAAiB,CAAC,EAEtBxB,EAAU,IAAM,CACTwB,EAAkB,WAAW,CACpC,EAAG,CAACA,CAAiB,CAAC,EAEtBxB,EAAU,IACD,IAAM,CACXG,EAAkB,cAAc,CAClC,EACC,CAAC,CAAC,EAEE,CACL,kBAAAqB,EACA,eAAAZ,CACF,CACF","names":["jsx","deriveAuthState","React","useEffect","useMemo","useState","IsoTernSecureAuth","AuthProviderCtx","IsoTernSecureAuthCtx","TernSecureCtxProvider","props","children","initialState","instanceOptions","instance","instanceStatus","useInitTernSecureAuth","authState","setAuthState","e","derivedState","sessionClaims","user","userId","authCtx","ternAuthCtx","options","isoTernSecureAuth","setInstanceStatus"]}
|
package/dist/hooks/useAuth.d.mts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { UseAuthReturn } from '@tern-secure/types';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
type UseAuthOptions = Record<string, any> | undefined | null;
|
|
7
|
+
declare const useAuth: (initialAuthStateOrOptions?: UseAuthOptions) => UseAuthReturn;
|
|
4
8
|
declare function useDeriveAuth(authObject: any): UseAuthReturn;
|
|
5
9
|
|
|
6
10
|
export { useAuth, useDeriveAuth };
|
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { UseAuthReturn } from '@tern-secure/types';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
type UseAuthOptions = Record<string, any> | undefined | null;
|
|
7
|
+
declare const useAuth: (initialAuthStateOrOptions?: UseAuthOptions) => UseAuthReturn;
|
|
4
8
|
declare function useDeriveAuth(authObject: any): UseAuthReturn;
|
|
5
9
|
|
|
6
10
|
export { useAuth, useDeriveAuth };
|
package/dist/hooks/useAuth.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var o=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},m=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let u of O(e))!g.call(t,u)&&u!==n&&o(t,u,{get:()=>e[u],enumerable:!(s=S(e,u))||s.enumerable});return t};var y=t=>m(o({},"__esModule",{value:!0}),t);var x={};p(x,{useAuth:()=>T,useDeriveAuth:()=>f});module.exports=y(x);var d=require("react"),c=require("../ctx/AuthProvider"),l=require("../ctx/IsomorphicTernSecureCtx"),h=require("./useAssertWrappedTernSecureProvider");const U=t=>async e=>{try{e?.onBeforeSignOut&&await e.onBeforeSignOut(),await t.signOut(e),e?.onAfterSignOut&&await e.onAfterSignOut()}catch(n){throw console.error("[useAuth] Sign out failed:",n),n}},T=(t={})=>{(0,h.useAssertWrappedByTernSecureAuthProvider)("useAuth");const{...e}=t??{},n=e;let u=(0,c.useAuthProviderCtx)();u.user===void 0&&(u=n??{});const i=(0,l.useIsoTernSecureAuthCtx)(),r=(0,d.useCallback)(U(i),[i]);return f({...u,signOut:r})};function f(t){const{signOut:e}=t??{},n=v({authObject:{...t,signOut:e}});if(!n)throw new Error("[useDeriveAuth] Unable to derive auth state.");return n}const b=(t,e,n)=>t?e?n?"authenticated":"unverified":"unauthenticated":"loading",v=({authObject:{userId:t,user:e,sessionClaims:n,signOut:s}})=>{if(!e)return{isLoaded:!1,isVerified:!1,isAuthenticated:!1,isValid:!1,user:null,userId:null,sessionClaims:null,status:"loading",signOut:s};if(e){const r=e.emailVerified||!1,a=r,A=b(!0,a,r);return{isLoaded:!0,isValid:!0,user:e,userId:t,isAuthenticated:a,isVerified:r,status:A,sessionClaims:n,signOut:s}}};0&&(module.exports={useAuth,useDeriveAuth});
|
|
2
2
|
//# sourceMappingURL=useAuth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useAuth.ts"],"sourcesContent":["'use client';\r\n\r\nimport type {\r\n DecodedIdToken,\r\n SignOut,\r\n SignOutOptions,\r\n TernSecureUser,\r\n UseAuthReturn,\r\n} from '@tern-secure/types';\r\nimport { useCallback } from 'react';\r\n\r\nimport { useAuthProviderCtx } from '../ctx/AuthProvider';\r\nimport { useIsoTernSecureAuthCtx } from '../ctx/IsomorphicTernSecureCtx';\r\nimport type { IsoTernSecureAuth } from '../lib/isoTernSecureAuth';\r\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider';\r\n\r\n\r\nconst handleSignOut = (instance: IsoTernSecureAuth) => {\r\n return async (options?: SignOutOptions) => {\r\n try {\r\n if (options?.onBeforeSignOut) {\r\n await options.onBeforeSignOut();\r\n }\r\n\r\n await instance.signOut(options);\r\n\r\n if (options?.onAfterSignOut) {\r\n await options.onAfterSignOut();\r\n }\r\n } catch (error) {\r\n console.error('[useAuth] Sign out failed:', error);\r\n throw error;\r\n }\r\n };\r\n};\r\n\r\nexport const useAuth = (): UseAuthReturn => {\r\n useAssertWrappedByTernSecureAuthProvider('useAuth');\r\n\r\n const ctx = useAuthProviderCtx();\r\n let authCtx = ctx;\r\n\r\n if (authCtx.user === undefined) {\r\n authCtx =
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useAuth.ts"],"sourcesContent":["'use client';\r\n\r\nimport type {\r\n DecodedIdToken,\r\n SignOut,\r\n SignOutOptions,\r\n TernSecureUser,\r\n UseAuthReturn,\r\n} from '@tern-secure/types';\r\nimport { useCallback } from 'react';\r\n\r\nimport { useAuthProviderCtx } from '../ctx/AuthProvider';\r\nimport { useIsoTernSecureAuthCtx } from '../ctx/IsomorphicTernSecureCtx';\r\nimport type { IsoTernSecureAuth } from '../lib/isoTernSecureAuth';\r\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider';\r\n\r\n\r\n/**\r\n * @inline\r\n */\r\ntype UseAuthOptions = Record<string, any> | undefined | null;\r\n\r\nconst handleSignOut = (instance: IsoTernSecureAuth) => {\r\n return async (options?: SignOutOptions) => {\r\n try {\r\n if (options?.onBeforeSignOut) {\r\n await options.onBeforeSignOut();\r\n }\r\n\r\n await instance.signOut(options);\r\n\r\n if (options?.onAfterSignOut) {\r\n await options.onAfterSignOut();\r\n }\r\n } catch (error) {\r\n console.error('[useAuth] Sign out failed:', error);\r\n throw error;\r\n }\r\n };\r\n};\r\n\r\nexport const useAuth = (initialAuthStateOrOptions: UseAuthOptions = {}): UseAuthReturn => {\r\n useAssertWrappedByTernSecureAuthProvider('useAuth');\r\n\r\n const { ...rest } = initialAuthStateOrOptions ?? {};\r\n const initialAuthState = rest as any;\r\n\r\n const ctx = useAuthProviderCtx();\r\n let authCtx = ctx;\r\n\r\n if (authCtx.user === undefined) {\r\n authCtx = initialAuthState != null ? initialAuthState : {};\r\n }\r\n\r\n const instance = useIsoTernSecureAuthCtx();\r\n const signOut: SignOut = useCallback(handleSignOut(instance), [instance]);\r\n\r\n return useDeriveAuth({ ...authCtx, signOut });\r\n};\r\n\r\nexport function useDeriveAuth(authObject: any): UseAuthReturn {\r\n const { signOut } = authObject ?? {};\r\n const payload = resolvedAuthState({ authObject: { ...authObject, signOut } });\r\n\r\n if (!payload) {\r\n throw new Error('[useDeriveAuth] Unable to derive auth state.');\r\n }\r\n return payload;\r\n}\r\n\r\nconst deriveAuthStatus = (\r\n isLoaded: boolean,\r\n isAuthenticated: boolean,\r\n isVerified: boolean,\r\n): UseAuthReturn['status'] => {\r\n if (!isLoaded) return 'loading';\r\n if (!isAuthenticated) return 'unauthenticated';\r\n if (!isVerified) return 'unverified';\r\n return 'authenticated';\r\n};\r\n\r\ntype AuthStateOptions = {\r\n authObject: {\r\n userId?: string | null;\r\n user?: TernSecureUser | null;\r\n sessionClaims?: DecodedIdToken | null;\r\n signOut: SignOut;\r\n };\r\n};\r\n\r\nconst resolvedAuthState = ({\r\n authObject: { userId, user, sessionClaims, signOut },\r\n}: AuthStateOptions): UseAuthReturn | undefined => {\r\n if (!user) {\r\n return {\r\n isLoaded: false,\r\n isVerified: false,\r\n isAuthenticated: false,\r\n isValid: false,\r\n user: null,\r\n userId: null,\r\n sessionClaims: null,\r\n status: 'loading',\r\n signOut,\r\n } as const;\r\n }\r\n\r\n if (user) {\r\n const isLoaded = true;\r\n const isValid = true;\r\n const isVerified = user.emailVerified || false;\r\n const isAuthenticated = isValid && isVerified;\r\n const status = deriveAuthStatus(isLoaded, isAuthenticated, isVerified);\r\n return {\r\n isLoaded,\r\n isValid,\r\n user,\r\n userId,\r\n isAuthenticated,\r\n isVerified,\r\n status,\r\n sessionClaims,\r\n signOut,\r\n } as const;\r\n }\r\n};\r\n"],"mappings":"sbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,kBAAAC,IAAA,eAAAC,EAAAJ,GASA,IAAAK,EAA4B,iBAE5BC,EAAmC,+BACnCC,EAAwC,0CAExCC,EAAyD,gDAQzD,MAAMC,EAAiBC,GACd,MAAOC,GAA6B,CACzC,GAAI,CACEA,GAAS,iBACX,MAAMA,EAAQ,gBAAgB,EAGhC,MAAMD,EAAS,QAAQC,CAAO,EAE1BA,GAAS,gBACX,MAAMA,EAAQ,eAAe,CAEjC,OAASC,EAAO,CACd,cAAQ,MAAM,6BAA8BA,CAAK,EAC3CA,CACR,CACF,EAGWV,EAAU,CAACW,EAA4C,CAAC,IAAqB,IACxF,4CAAyC,SAAS,EAElD,KAAM,CAAE,GAAGC,CAAK,EAAID,GAA6B,CAAC,EAC5CE,EAAmBD,EAGzB,IAAIE,KADQ,sBAAmB,EAG3BA,EAAQ,OAAS,SACnBA,EAAUD,GAA8C,CAAC,GAG3D,MAAML,KAAW,2BAAwB,EACnCO,KAAmB,eAAYR,EAAcC,CAAQ,EAAG,CAACA,CAAQ,CAAC,EAExE,OAAOP,EAAc,CAAE,GAAGa,EAAS,QAAAC,CAAQ,CAAC,CAC9C,EAEO,SAASd,EAAce,EAAgC,CAC5D,KAAM,CAAE,QAAAD,CAAQ,EAAIC,GAAc,CAAC,EAC7BC,EAAUC,EAAkB,CAAE,WAAY,CAAE,GAAGF,EAAY,QAAAD,CAAQ,CAAE,CAAC,EAE5E,GAAI,CAACE,EACH,MAAM,IAAI,MAAM,8CAA8C,EAEhE,OAAOA,CACT,CAEA,MAAME,EAAmB,CACvBC,EACAC,EACAC,IAEKF,EACAC,EACAC,EACE,gBADiB,aADK,kBADP,UAelBJ,EAAoB,CAAC,CACzB,WAAY,CAAE,OAAAK,EAAQ,KAAAC,EAAM,cAAAC,EAAe,QAAAV,CAAQ,CACrD,IAAmD,CACjD,GAAI,CAACS,EACH,MAAO,CACL,SAAU,GACV,WAAY,GACZ,gBAAiB,GACjB,QAAS,GACT,KAAM,KACN,OAAQ,KACR,cAAe,KACf,OAAQ,UACR,QAAAT,CACF,EAGF,GAAIS,EAAM,CAGR,MAAMF,EAAaE,EAAK,eAAiB,GACnCH,EAA6BC,EAC7BI,EAASP,EAAiB,GAAUE,EAAiBC,CAAU,EACrE,MAAO,CACL,YACA,WACA,KAAAE,EACA,OAAAD,EACA,gBAAAF,EACA,WAAAC,EACA,OAAAI,EACA,cAAAD,EACA,QAAAV,CACF,CACF,CACF","names":["useAuth_exports","__export","useAuth","useDeriveAuth","__toCommonJS","import_react","import_AuthProvider","import_IsomorphicTernSecureCtx","import_useAssertWrappedTernSecureProvider","handleSignOut","instance","options","error","initialAuthStateOrOptions","rest","initialAuthState","authCtx","signOut","authObject","payload","resolvedAuthState","deriveAuthStatus","isLoaded","isAuthenticated","isVerified","userId","user","sessionClaims","status"]}
|
package/dist/hooks/useAuth.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCallback as
|
|
1
|
+
"use client";import{useCallback as d}from"react";import{useAuthProviderCtx as c}from"../ctx/AuthProvider";import{useIsoTernSecureAuthCtx as l}from"../ctx/IsomorphicTernSecureCtx";import{useAssertWrappedByTernSecureAuthProvider as h}from"./useAssertWrappedTernSecureProvider";const f=n=>async e=>{try{e?.onBeforeSignOut&&await e.onBeforeSignOut(),await n.signOut(e),e?.onAfterSignOut&&await e.onAfterSignOut()}catch(t){throw console.error("[useAuth] Sign out failed:",t),t}},U=(n={})=>{h("useAuth");const{...e}=n??{},t=e;let s=c();s.user===void 0&&(s=t??{});const i=l(),u=d(f(i),[i]);return A({...s,signOut:u})};function A(n){const{signOut:e}=n??{},t=O({authObject:{...n,signOut:e}});if(!t)throw new Error("[useDeriveAuth] Unable to derive auth state.");return t}const S=(n,e,t)=>n?e?t?"authenticated":"unverified":"unauthenticated":"loading",O=({authObject:{userId:n,user:e,sessionClaims:t,signOut:r}})=>{if(!e)return{isLoaded:!1,isVerified:!1,isAuthenticated:!1,isValid:!1,user:null,userId:null,sessionClaims:null,status:"loading",signOut:r};if(e){const u=e.emailVerified||!1,o=u,a=S(!0,o,u);return{isLoaded:!0,isValid:!0,user:e,userId:n,isAuthenticated:o,isVerified:u,status:a,sessionClaims:t,signOut:r}}};export{U as useAuth,A as useDeriveAuth};
|
|
2
2
|
//# sourceMappingURL=useAuth.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useAuth.ts"],"sourcesContent":["'use client';\r\n\r\nimport type {\r\n DecodedIdToken,\r\n SignOut,\r\n SignOutOptions,\r\n TernSecureUser,\r\n UseAuthReturn,\r\n} from '@tern-secure/types';\r\nimport { useCallback } from 'react';\r\n\r\nimport { useAuthProviderCtx } from '../ctx/AuthProvider';\r\nimport { useIsoTernSecureAuthCtx } from '../ctx/IsomorphicTernSecureCtx';\r\nimport type { IsoTernSecureAuth } from '../lib/isoTernSecureAuth';\r\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider';\r\n\r\n\r\nconst handleSignOut = (instance: IsoTernSecureAuth) => {\r\n return async (options?: SignOutOptions) => {\r\n try {\r\n if (options?.onBeforeSignOut) {\r\n await options.onBeforeSignOut();\r\n }\r\n\r\n await instance.signOut(options);\r\n\r\n if (options?.onAfterSignOut) {\r\n await options.onAfterSignOut();\r\n }\r\n } catch (error) {\r\n console.error('[useAuth] Sign out failed:', error);\r\n throw error;\r\n }\r\n };\r\n};\r\n\r\nexport const useAuth = (): UseAuthReturn => {\r\n useAssertWrappedByTernSecureAuthProvider('useAuth');\r\n\r\n const ctx = useAuthProviderCtx();\r\n let authCtx = ctx;\r\n\r\n if (authCtx.user === undefined) {\r\n authCtx =
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useAuth.ts"],"sourcesContent":["'use client';\r\n\r\nimport type {\r\n DecodedIdToken,\r\n SignOut,\r\n SignOutOptions,\r\n TernSecureUser,\r\n UseAuthReturn,\r\n} from '@tern-secure/types';\r\nimport { useCallback } from 'react';\r\n\r\nimport { useAuthProviderCtx } from '../ctx/AuthProvider';\r\nimport { useIsoTernSecureAuthCtx } from '../ctx/IsomorphicTernSecureCtx';\r\nimport type { IsoTernSecureAuth } from '../lib/isoTernSecureAuth';\r\nimport { useAssertWrappedByTernSecureAuthProvider } from './useAssertWrappedTernSecureProvider';\r\n\r\n\r\n/**\r\n * @inline\r\n */\r\ntype UseAuthOptions = Record<string, any> | undefined | null;\r\n\r\nconst handleSignOut = (instance: IsoTernSecureAuth) => {\r\n return async (options?: SignOutOptions) => {\r\n try {\r\n if (options?.onBeforeSignOut) {\r\n await options.onBeforeSignOut();\r\n }\r\n\r\n await instance.signOut(options);\r\n\r\n if (options?.onAfterSignOut) {\r\n await options.onAfterSignOut();\r\n }\r\n } catch (error) {\r\n console.error('[useAuth] Sign out failed:', error);\r\n throw error;\r\n }\r\n };\r\n};\r\n\r\nexport const useAuth = (initialAuthStateOrOptions: UseAuthOptions = {}): UseAuthReturn => {\r\n useAssertWrappedByTernSecureAuthProvider('useAuth');\r\n\r\n const { ...rest } = initialAuthStateOrOptions ?? {};\r\n const initialAuthState = rest as any;\r\n\r\n const ctx = useAuthProviderCtx();\r\n let authCtx = ctx;\r\n\r\n if (authCtx.user === undefined) {\r\n authCtx = initialAuthState != null ? initialAuthState : {};\r\n }\r\n\r\n const instance = useIsoTernSecureAuthCtx();\r\n const signOut: SignOut = useCallback(handleSignOut(instance), [instance]);\r\n\r\n return useDeriveAuth({ ...authCtx, signOut });\r\n};\r\n\r\nexport function useDeriveAuth(authObject: any): UseAuthReturn {\r\n const { signOut } = authObject ?? {};\r\n const payload = resolvedAuthState({ authObject: { ...authObject, signOut } });\r\n\r\n if (!payload) {\r\n throw new Error('[useDeriveAuth] Unable to derive auth state.');\r\n }\r\n return payload;\r\n}\r\n\r\nconst deriveAuthStatus = (\r\n isLoaded: boolean,\r\n isAuthenticated: boolean,\r\n isVerified: boolean,\r\n): UseAuthReturn['status'] => {\r\n if (!isLoaded) return 'loading';\r\n if (!isAuthenticated) return 'unauthenticated';\r\n if (!isVerified) return 'unverified';\r\n return 'authenticated';\r\n};\r\n\r\ntype AuthStateOptions = {\r\n authObject: {\r\n userId?: string | null;\r\n user?: TernSecureUser | null;\r\n sessionClaims?: DecodedIdToken | null;\r\n signOut: SignOut;\r\n };\r\n};\r\n\r\nconst resolvedAuthState = ({\r\n authObject: { userId, user, sessionClaims, signOut },\r\n}: AuthStateOptions): UseAuthReturn | undefined => {\r\n if (!user) {\r\n return {\r\n isLoaded: false,\r\n isVerified: false,\r\n isAuthenticated: false,\r\n isValid: false,\r\n user: null,\r\n userId: null,\r\n sessionClaims: null,\r\n status: 'loading',\r\n signOut,\r\n } as const;\r\n }\r\n\r\n if (user) {\r\n const isLoaded = true;\r\n const isValid = true;\r\n const isVerified = user.emailVerified || false;\r\n const isAuthenticated = isValid && isVerified;\r\n const status = deriveAuthStatus(isLoaded, isAuthenticated, isVerified);\r\n return {\r\n isLoaded,\r\n isValid,\r\n user,\r\n userId,\r\n isAuthenticated,\r\n isVerified,\r\n status,\r\n sessionClaims,\r\n signOut,\r\n } as const;\r\n }\r\n};\r\n"],"mappings":"aASA,OAAS,eAAAA,MAAmB,QAE5B,OAAS,sBAAAC,MAA0B,sBACnC,OAAS,2BAAAC,MAA+B,iCAExC,OAAS,4CAAAC,MAAgD,uCAQzD,MAAMC,EAAiBC,GACd,MAAOC,GAA6B,CACzC,GAAI,CACEA,GAAS,iBACX,MAAMA,EAAQ,gBAAgB,EAGhC,MAAMD,EAAS,QAAQC,CAAO,EAE1BA,GAAS,gBACX,MAAMA,EAAQ,eAAe,CAEjC,OAASC,EAAO,CACd,cAAQ,MAAM,6BAA8BA,CAAK,EAC3CA,CACR,CACF,EAGWC,EAAU,CAACC,EAA4C,CAAC,IAAqB,CACxFN,EAAyC,SAAS,EAElD,KAAM,CAAE,GAAGO,CAAK,EAAID,GAA6B,CAAC,EAC5CE,EAAmBD,EAGzB,IAAIE,EADQX,EAAmB,EAG3BW,EAAQ,OAAS,SACnBA,EAAUD,GAA8C,CAAC,GAG3D,MAAMN,EAAWH,EAAwB,EACnCW,EAAmBb,EAAYI,EAAcC,CAAQ,EAAG,CAACA,CAAQ,CAAC,EAExE,OAAOS,EAAc,CAAE,GAAGF,EAAS,QAAAC,CAAQ,CAAC,CAC9C,EAEO,SAASC,EAAcC,EAAgC,CAC5D,KAAM,CAAE,QAAAF,CAAQ,EAAIE,GAAc,CAAC,EAC7BC,EAAUC,EAAkB,CAAE,WAAY,CAAE,GAAGF,EAAY,QAAAF,CAAQ,CAAE,CAAC,EAE5E,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,8CAA8C,EAEhE,OAAOA,CACT,CAEA,MAAME,EAAmB,CACvBC,EACAC,EACAC,IAEKF,EACAC,EACAC,EACE,gBADiB,aADK,kBADP,UAelBJ,EAAoB,CAAC,CACzB,WAAY,CAAE,OAAAK,EAAQ,KAAAC,EAAM,cAAAC,EAAe,QAAAX,CAAQ,CACrD,IAAmD,CACjD,GAAI,CAACU,EACH,MAAO,CACL,SAAU,GACV,WAAY,GACZ,gBAAiB,GACjB,QAAS,GACT,KAAM,KACN,OAAQ,KACR,cAAe,KACf,OAAQ,UACR,QAAAV,CACF,EAGF,GAAIU,EAAM,CAGR,MAAMF,EAAaE,EAAK,eAAiB,GACnCH,EAA6BC,EAC7BI,EAASP,EAAiB,GAAUE,EAAiBC,CAAU,EACrE,MAAO,CACL,YACA,WACA,KAAAE,EACA,OAAAD,EACA,gBAAAF,EACA,WAAAC,EACA,OAAAI,EACA,cAAAD,EACA,QAAAX,CACF,CACF,CACF","names":["useCallback","useAuthProviderCtx","useIsoTernSecureAuthCtx","useAssertWrappedByTernSecureAuthProvider","handleSignOut","instance","options","error","useAuth","initialAuthStateOrOptions","rest","initialAuthState","authCtx","signOut","useDeriveAuth","authObject","payload","resolvedAuthState","deriveAuthStatus","isLoaded","isAuthenticated","isVerified","userId","user","sessionClaims","status"]}
|
|
@@ -1,2 +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 g=r=>S(u({},"__esModule",{value:!0}),r);var T={};f(T,{IsoTernSecureAuth:()=>h,inBrowser:()=>a});module.exports=g(T);var c=require("@tern-secure/auth"),s=require("@tern-secure/shared/ternStatusEvent"),o=require("@tern-secure/shared/utils");const A={name:"@tern-secure/react",version:"1.2.0-canary.
|
|
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 g=r=>S(u({},"__esModule",{value:!0}),r);var T={};f(T,{IsoTernSecureAuth:()=>h,inBrowser:()=>a});module.exports=g(T);var c=require("@tern-secure/auth"),s=require("@tern-secure/shared/ternStatusEvent"),o=require("@tern-secure/shared/utils");const A={name:"@tern-secure/react",version:"1.2.0-canary.v20251030165007",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||void 0}get signUp(){if(this.ternauth)return this.ternauth.signUp||void 0}get user(){return this.ternauth?this.ternauth.user:null}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}_internal_getOption(e){return this.ternauth?._internal_getOption?this.ternauth?._internal_getOption(e):this.options[e]}_internal_getAllOptions(){return Object.freeze({...this.options})}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=A)}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||""}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}};createActiveSession=e=>this.ternauth?this.ternauth.createActiveSession(e):Promise.reject(new Error("TernSecureAuth not initialized"));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"),()=>{})}getRedirectResult=async()=>{if(!this.ternauth?.getRedirectResult)throw new Error("TernSecure instance not initialized");return this.ternauth.getRedirectResult()};constructUrlWithAuthRedirect=e=>this.ternauth&&this.isReady?this.ternauth.constructUrlWithAuthRedirect(e):"";navigate=e=>{this.ternauth&&this.isReady&&this.ternauth.navigate(e)};redirectToSignIn=async e=>{this.ternauth?.redirectToSignIn&&this.ternauth.redirectToSignIn(e)};redirectToSignUp=async e=>{this.ternauth?.redirectToSignUp&&this.ternauth.redirectToSignUp()};redirectAfterSignIn=e=>{this.ternauth?.redirectAfterSignIn&&this.ternauth.redirectAfterSignIn()};redirectAfterSignUp=e=>{this.ternauth?.redirectAfterSignUp&&this.ternauth.redirectAfterSignUp()};#u(){return new Promise(e=>{e(this.ternauth)})}initialize=async()=>{this.initTernSecureAuth();try{await this.#u()}catch(e){throw console.error("[IsomorphicTernSecure] Failed to initialize TernSecureAuth:",e),e}}}0&&(module.exports={IsoTernSecureAuth,inBrowser});
|
|
2
2
|
//# sourceMappingURL=isoTernSecureAuth.js.map
|
|
@@ -1,2 +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.2.0-canary.
|
|
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.2.0-canary.v20251030165007",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||void 0}get signUp(){if(this.ternauth)return this.ternauth.signUp||void 0}get user(){return this.ternauth?this.ternauth.user:null}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}_internal_getOption(e){return this.ternauth?._internal_getOption?this.ternauth?._internal_getOption(e):this.options[e]}_internal_getAllOptions(){return Object.freeze({...this.options})}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)}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||""}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}};createActiveSession=e=>this.ternauth?this.ternauth.createActiveSession(e):Promise.reject(new Error("TernSecureAuth not initialized"));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"),()=>{})}getRedirectResult=async()=>{if(!this.ternauth?.getRedirectResult)throw new Error("TernSecure instance not initialized");return this.ternauth.getRedirectResult()};constructUrlWithAuthRedirect=e=>this.ternauth&&this.isReady?this.ternauth.constructUrlWithAuthRedirect(e):"";navigate=e=>{this.ternauth&&this.isReady&&this.ternauth.navigate(e)};redirectToSignIn=async e=>{this.ternauth?.redirectToSignIn&&this.ternauth.redirectToSignIn(e)};redirectToSignUp=async e=>{this.ternauth?.redirectToSignUp&&this.ternauth.redirectToSignUp()};redirectAfterSignIn=e=>{this.ternauth?.redirectAfterSignIn&&this.ternauth.redirectAfterSignIn()};redirectAfterSignUp=e=>{this.ternauth?.redirectAfterSignUp&&this.ternauth.redirectAfterSignUp()};#u(){return new Promise(e=>{e(this.ternauth)})}initialize=async()=>{this.initTernSecureAuth();try{await this.#u()}catch(e){throw console.error("[IsomorphicTernSecure] Failed to initialize TernSecureAuth:",e),e}}}export{s as IsoTernSecureAuth,i as inBrowser};
|
|
2
2
|
//# sourceMappingURL=isoTernSecureAuth.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tern-secure/react",
|
|
3
|
-
"version": "1.2.0-canary.
|
|
3
|
+
"version": "1.2.0-canary.v20251030165007",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TernSecure/auth.git",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"tailwind-merge": "^2.5.5",
|
|
37
37
|
"tailwindcss-animate": "^1.0.7",
|
|
38
38
|
"tslib": "2.4.1",
|
|
39
|
-
"@tern-secure/auth": "1.1.0-canary.
|
|
40
|
-
"@tern-secure/shared": "1.3.0-canary.
|
|
41
|
-
"@tern-secure/types": "1.1.0-canary.
|
|
39
|
+
"@tern-secure/auth": "1.1.0-canary.v20251030165007",
|
|
40
|
+
"@tern-secure/shared": "1.3.0-canary.v20251030165007",
|
|
41
|
+
"@tern-secure/types": "1.1.0-canary.v20251030165007"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tailwindcss/cli": "^4.1.6",
|