@tern-secure/react 1.2.0-canary.v20251003171521 → 1.2.0-canary.v20251008165428
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/SignInCtx.d.mts +22 -0
- package/dist/ctx/SignInCtx.d.ts +22 -0
- package/dist/ctx/SignInCtx.js +2 -0
- package/dist/ctx/SignInCtx.js.map +1 -0
- package/dist/ctx/SignInCtx.mjs +2 -0
- package/dist/ctx/SignInCtx.mjs.map +1 -0
- 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/useSignIn.d.mts +4 -4
- package/dist/hooks/useSignIn.d.ts +4 -4
- package/dist/hooks/useSignIn.js +1 -1
- package/dist/hooks/useSignIn.js.map +1 -1
- package/dist/hooks/useSignIn.mjs +1 -1
- package/dist/hooks/useSignIn.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- 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 +14 -1
- package/dist/lib/isoTernSecureAuth.d.ts +14 -1
- package/dist/lib/isoTernSecureAuth.js +1 -1
- package/dist/lib/isoTernSecureAuth.js.map +1 -1
- package/dist/lib/isoTernSecureAuth.mjs +1 -1
- package/dist/lib/isoTernSecureAuth.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SignInProps, SignInRedirectUrl, SignUpRedirectUrl, TernSecureUser, AuthErrorTree } from '@tern-secure/auth';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type SignInCtx = SignInProps & SignInRedirectUrl & SignUpRedirectUrl;
|
|
6
|
+
interface SignInContextType extends Omit<SignInCtx, 'forceRedirectUrl' | 'signInForceRedirectUrl'> {
|
|
7
|
+
handleSignInSuccess: (user?: TernSecureUser | null, options?: {
|
|
8
|
+
skipRedirect?: boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
handleSignInError: (error: AuthErrorTree) => void;
|
|
11
|
+
redirectAfterSignIn: () => void;
|
|
12
|
+
SignInUrl: string;
|
|
13
|
+
SignUpUrl: string;
|
|
14
|
+
checkRedirectResult: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
declare const useSignInContext: () => SignInContextType;
|
|
17
|
+
interface SignInProviderProps extends Partial<SignInCtx> {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
declare function SignInProvider({ children, onSuccess, forceRedirectUrl, signInForceRedirectUrl, signUpForceRedirectUrl, ...ctxProps }: SignInProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { type SignInCtx, SignInProvider, useSignInContext };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SignInProps, SignInRedirectUrl, SignUpRedirectUrl, TernSecureUser, AuthErrorTree } from '@tern-secure/auth';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type SignInCtx = SignInProps & SignInRedirectUrl & SignUpRedirectUrl;
|
|
6
|
+
interface SignInContextType extends Omit<SignInCtx, 'forceRedirectUrl' | 'signInForceRedirectUrl'> {
|
|
7
|
+
handleSignInSuccess: (user?: TernSecureUser | null, options?: {
|
|
8
|
+
skipRedirect?: boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
handleSignInError: (error: AuthErrorTree) => void;
|
|
11
|
+
redirectAfterSignIn: () => void;
|
|
12
|
+
SignInUrl: string;
|
|
13
|
+
SignUpUrl: string;
|
|
14
|
+
checkRedirectResult: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
declare const useSignInContext: () => SignInContextType;
|
|
17
|
+
interface SignInProviderProps extends Partial<SignInCtx> {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
declare function SignInProvider({ children, onSuccess, forceRedirectUrl, signInForceRedirectUrl, signUpForceRedirectUrl, ...ctxProps }: SignInProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { type SignInCtx, SignInProvider, useSignInContext };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";"use client";var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var s in e)p(t,s,{get:e[s],enumerable:!0})},O=(t,e,s,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of w(e))!F.call(t,o)&&o!==s&&p(t,o,{get:()=>e[o],enumerable:!(u=b(e,o))||u.enumerable});return t};var _=t=>O(p({},"__esModule",{value:!0}),t);var H={};L(H,{SignInProvider:()=>N,useSignInContext:()=>D});module.exports=_(H);var x=require("react/jsx-runtime"),I=require("@tern-secure/auth"),P=require("@tern-secure/shared/react"),n=require("react");const m=(0,n.createContext)({handleSignInSuccess:()=>{},handleSignInError:()=>{},redirectAfterSignIn:()=>{},SignInUrl:"",SignUpUrl:"",checkRedirectResult:async()=>{}}),D=()=>(0,n.useContext)(m);function N({children:t,onSuccess:e,forceRedirectUrl:s,signInForceRedirectUrl:u,signUpForceRedirectUrl:o,...C}){const c=(0,P.useTernSecure)(),U=c._internal_getAllOptions(),R=(0,n.useMemo)(()=>typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,[]),S=(0,n.useCallback)((r,i,v="AuthError",k)=>{const d=new Error(r);return d.name=v,d.code=i,d.response=k,d},[]),g=(0,n.useCallback)(()=>{c.redirectAfterSignIn()},[c]),l=(0,n.useCallback)((r,i)=>{e?.(r||null),i?.skipRedirect||g()},[e,g]),a=(0,n.useCallback)(r=>{console.error(r)},[]),h=(0,n.useCallback)(async()=>{try{const r=await c.getRedirectResult();if(r&&r.success)l(r.user);else if(r&&!r.success){const i=S(r.message||"Redirect sign-in failed",r.error||"REDIRECT_FAILED","RedirectError",r);a(i)}}catch(r){const i=S(r instanceof Error?r.message:"Failed to check redirect result","REDIRECT_CHECK_FAILED","RedirectError",r);a(i)}},[c,l,a,S]),A=C.path||U.signInUrl,T=U.signUpUrl,f=(0,I.buildURL)({base:A,searchParams:R},{stringify:!0,skipOrigin:!1}),E=(0,I.buildURL)({base:T,searchParams:R},{stringify:!0,skipOrigin:!1}),y=(0,n.useMemo)(()=>({handleSignInSuccess:l,handleSignInError:a,redirectAfterSignIn:g,checkRedirectResult:h,SignInUrl:f,SignUpUrl:E,onSuccess:e}),[l,a,g,h,f,E,e]);return(0,x.jsx)(m.Provider,{value:y,children:t})}0&&(module.exports={SignInProvider,useSignInContext});
|
|
2
|
+
//# sourceMappingURL=SignInCtx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ctx/SignInCtx.tsx"],"sourcesContent":["'use client';\n\nimport type {\n AuthErrorTree,\n SignInProps,\n SignInRedirectUrl,\n SignUpRedirectUrl,\n TernSecureUser,\n} from '@tern-secure/auth';\nimport { buildURL } from '@tern-secure/auth';\nimport { useTernSecure } from '@tern-secure/shared/react';\nimport type { ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useMemo } from 'react';\n\n\nexport type SignInCtx = SignInProps & SignInRedirectUrl & SignUpRedirectUrl;\n\ninterface SignInContextType extends Omit<SignInCtx, 'forceRedirectUrl' | 'signInForceRedirectUrl'> {\n handleSignInSuccess: (user?: TernSecureUser | null, options?: { skipRedirect?: boolean }) => void;\n handleSignInError: (error: AuthErrorTree) => void;\n redirectAfterSignIn: () => void;\n SignInUrl: string;\n SignUpUrl: string;\n checkRedirectResult: () => Promise<void>;\n}\n\nconst SignInContext = createContext<SignInContextType>({\n handleSignInSuccess: () => {},\n handleSignInError: () => {},\n redirectAfterSignIn: () => {},\n SignInUrl: '',\n SignUpUrl: '',\n checkRedirectResult: async () => {},\n});\n\nexport const useSignInContext = () => useContext(SignInContext);\n\ninterface SignInProviderProps extends Partial<SignInCtx> {\n children: ReactNode;\n}\n\nexport function SignInProvider({\n children,\n onSuccess,\n forceRedirectUrl,\n signInForceRedirectUrl,\n signUpForceRedirectUrl,\n ...ctxProps\n}: SignInProviderProps) {\n const ternSecure = useTernSecure();\n const ternSecureOptions = ternSecure._internal_getAllOptions();\n const currentParams = useMemo(() => {\n if (typeof window !== 'undefined') {\n return new URLSearchParams(window.location.search);\n }\n return new URLSearchParams();\n }, []);\n\n const createAuthError = useCallback(\n (message: string, code: string, name: string = 'AuthError', response?: any): AuthErrorTree => {\n const authError = new Error(message) as AuthErrorTree;\n authError.name = name;\n authError.code = code;\n authError.response = response;\n return authError;\n },\n [],\n );\n\n const redirectAfterSignIn = useCallback(() => {\n ternSecure.redirectAfterSignIn();\n }, [ternSecure]);\n\n const handleSignInSuccess = useCallback(\n (user?: TernSecureUser | null, options?: { skipRedirect?: boolean }) => {\n onSuccess?.(user || null);\n if (!options?.skipRedirect) {\n redirectAfterSignIn();\n }\n },\n [onSuccess, redirectAfterSignIn],\n );\n\n const handleSignInError = useCallback(\n (authError: AuthErrorTree) => {\n console.error(authError);\n },\n [],\n );\n\n const checkRedirectResult = useCallback(async (): Promise<void> => {\n try {\n const result = await ternSecure.getRedirectResult();\n if (result && result.success) {\n handleSignInSuccess(result.user);\n } else if (result && !result.success) {\n const authError = createAuthError(\n result.message || 'Redirect sign-in failed',\n result.error || 'REDIRECT_FAILED',\n 'RedirectError',\n result,\n );\n handleSignInError(authError);\n }\n } catch (error) {\n const authError = createAuthError(\n error instanceof Error ? error.message : 'Failed to check redirect result',\n 'REDIRECT_CHECK_FAILED',\n 'RedirectError',\n error,\n );\n handleSignInError(authError);\n }\n }, [ternSecure, handleSignInSuccess, handleSignInError, createAuthError]);\n\n const baseSignInUrl = ctxProps.path || ternSecureOptions.signInUrl;\n const baseSignUpUrl = ternSecureOptions.signUpUrl;\n\n const SignInUrl = buildURL(\n {\n base: baseSignInUrl,\n searchParams: currentParams,\n },\n { stringify: true, skipOrigin: false },\n ) as string;\n\n const SignUpUrl = buildURL(\n {\n base: baseSignUpUrl,\n searchParams: currentParams,\n },\n { stringify: true, skipOrigin: false },\n ) as string;\n\n const contextValue: SignInContextType = useMemo(\n () => ({\n handleSignInSuccess,\n handleSignInError,\n redirectAfterSignIn,\n checkRedirectResult,\n SignInUrl,\n SignUpUrl,\n onSuccess,\n }),\n [\n handleSignInSuccess,\n handleSignInError,\n redirectAfterSignIn,\n checkRedirectResult,\n SignInUrl,\n SignUpUrl,\n onSuccess,\n ],\n );\n\n return <SignInContext.Provider value={contextValue}>{children}</SignInContext.Provider>;\n}\n"],"mappings":"sbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,qBAAAC,IAAA,eAAAC,EAAAJ,GA2JS,IAAAK,EAAA,6BAlJTC,EAAyB,6BACzBC,EAA8B,qCAE9BA,EAAgE,iBAchE,MAAMC,KAAgB,iBAAiC,CACrD,oBAAqB,IAAM,CAAC,EAC5B,kBAAmB,IAAM,CAAC,EAC1B,oBAAqB,IAAM,CAAC,EAC5B,UAAW,GACX,UAAW,GACX,oBAAqB,SAAY,CAAC,CACpC,CAAC,EAEYL,EAAmB,OAAM,cAAWK,CAAa,EAMvD,SAASN,EAAe,CAC7B,SAAAO,EACA,UAAAC,EACA,iBAAAC,EACA,uBAAAC,EACA,uBAAAC,EACA,GAAGC,CACL,EAAwB,CACtB,MAAMC,KAAa,iBAAc,EAC3BC,EAAoBD,EAAW,wBAAwB,EACvDE,KAAgB,WAAQ,IACxB,OAAO,OAAW,IACb,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAE5C,IAAI,gBACV,CAAC,CAAC,EAECC,KAAkB,eACtB,CAACC,EAAiBC,EAAcC,EAAe,YAAaC,I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C,EACA,UAAAzB,CACF,GACA,CACEe,EACAG,EACAJ,EACAK,EACAK,EACAC,EACAzB,CACF,CACF,EAEA,SAAO,OAACF,EAAc,SAAd,CAAuB,MAAO4B,EAAe,SAAA3B,EAAS,CAChE","names":["SignInCtx_exports","__export","SignInProvider","useSignInContext","__toCommonJS","import_jsx_runtime","import_auth","import_react","SignInContext","children","onSuccess","forceRedirectUrl","signInForceRedirectUrl","signUpForceRedirectUrl","ctxProps","ternSecure","ternSecureOptions","currentParams","createAuthError","message","code","name","response","authError","redirectAfterSignIn","handleSignInSuccess","user","options","handleSignInError","checkRedirectResult","result","error","baseSignInUrl","baseSignUpUrl","SignInUrl","SignUpUrl","contextValue"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{jsx as v}from"react/jsx-runtime";import{buildURL as I}from"@tern-secure/auth";import{useTernSecure as A}from"@tern-secure/shared/react";import{createContext as T,useCallback as i,useContext as y,useMemo as U}from"react";const R=T({handleSignInSuccess:()=>{},handleSignInError:()=>{},redirectAfterSignIn:()=>{},SignInUrl:"",SignUpUrl:"",checkRedirectResult:async()=>{}}),_=()=>y(R);function D({children:h,onSuccess:o,forceRedirectUrl:k,signInForceRedirectUrl:b,signUpForceRedirectUrl:w,...f}){const n=A(),l=n._internal_getAllOptions(),d=U(()=>typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,[]),g=i((r,e,x="AuthError",C)=>{const a=new Error(r);return a.name=x,a.code=e,a.response=C,a},[]),s=i(()=>{n.redirectAfterSignIn()},[n]),c=i((r,e)=>{o?.(r||null),e?.skipRedirect||s()},[o,s]),t=i(r=>{console.error(r)},[]),u=i(async()=>{try{const r=await n.getRedirectResult();if(r&&r.success)c(r.user);else if(r&&!r.success){const e=g(r.message||"Redirect sign-in failed",r.error||"REDIRECT_FAILED","RedirectError",r);t(e)}}catch(r){const e=g(r instanceof Error?r.message:"Failed to check redirect result","REDIRECT_CHECK_FAILED","RedirectError",r);t(e)}},[n,c,t,g]),E=f.path||l.signInUrl,m=l.signUpUrl,S=I({base:E,searchParams:d},{stringify:!0,skipOrigin:!1}),p=I({base:m,searchParams:d},{stringify:!0,skipOrigin:!1}),P=U(()=>({handleSignInSuccess:c,handleSignInError:t,redirectAfterSignIn:s,checkRedirectResult:u,SignInUrl:S,SignUpUrl:p,onSuccess:o}),[c,t,s,u,S,p,o]);return v(R.Provider,{value:P,children:h})}export{D as SignInProvider,_ as useSignInContext};
|
|
2
|
+
//# sourceMappingURL=SignInCtx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ctx/SignInCtx.tsx"],"sourcesContent":["'use client';\n\nimport type {\n AuthErrorTree,\n SignInProps,\n SignInRedirectUrl,\n SignUpRedirectUrl,\n TernSecureUser,\n} from '@tern-secure/auth';\nimport { buildURL } from '@tern-secure/auth';\nimport { useTernSecure } from '@tern-secure/shared/react';\nimport type { ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useMemo } from 'react';\n\n\nexport type SignInCtx = SignInProps & SignInRedirectUrl & SignUpRedirectUrl;\n\ninterface SignInContextType extends Omit<SignInCtx, 'forceRedirectUrl' | 'signInForceRedirectUrl'> {\n handleSignInSuccess: (user?: TernSecureUser | null, options?: { skipRedirect?: boolean }) => void;\n handleSignInError: (error: AuthErrorTree) => void;\n redirectAfterSignIn: () => void;\n SignInUrl: string;\n SignUpUrl: string;\n checkRedirectResult: () => Promise<void>;\n}\n\nconst SignInContext = createContext<SignInContextType>({\n handleSignInSuccess: () => {},\n handleSignInError: () => {},\n redirectAfterSignIn: () => {},\n SignInUrl: '',\n SignUpUrl: '',\n checkRedirectResult: async () => {},\n});\n\nexport const useSignInContext = () => useContext(SignInContext);\n\ninterface SignInProviderProps extends Partial<SignInCtx> {\n children: ReactNode;\n}\n\nexport function SignInProvider({\n children,\n onSuccess,\n forceRedirectUrl,\n signInForceRedirectUrl,\n signUpForceRedirectUrl,\n ...ctxProps\n}: SignInProviderProps) {\n const ternSecure = useTernSecure();\n const ternSecureOptions = ternSecure._internal_getAllOptions();\n const currentParams = useMemo(() => {\n if (typeof window !== 'undefined') {\n return new URLSearchParams(window.location.search);\n }\n return new URLSearchParams();\n }, []);\n\n const createAuthError = useCallback(\n (message: string, code: string, name: string = 'AuthError', response?: any): AuthErrorTree => {\n const authError = new Error(message) as AuthErrorTree;\n authError.name = name;\n authError.code = code;\n authError.response = response;\n return authError;\n },\n [],\n );\n\n const redirectAfterSignIn = useCallback(() => {\n ternSecure.redirectAfterSignIn();\n }, [ternSecure]);\n\n const handleSignInSuccess = useCallback(\n (user?: TernSecureUser | null, options?: { skipRedirect?: boolean }) => {\n onSuccess?.(user || null);\n if (!options?.skipRedirect) {\n redirectAfterSignIn();\n }\n },\n [onSuccess, redirectAfterSignIn],\n );\n\n const handleSignInError = useCallback(\n (authError: AuthErrorTree) => {\n console.error(authError);\n },\n [],\n );\n\n const checkRedirectResult = useCallback(async (): Promise<void> => {\n try {\n const result = await ternSecure.getRedirectResult();\n if (result && result.success) {\n handleSignInSuccess(result.user);\n } else if (result && !result.success) {\n const authError = createAuthError(\n result.message || 'Redirect sign-in failed',\n result.error || 'REDIRECT_FAILED',\n 'RedirectError',\n result,\n );\n handleSignInError(authError);\n }\n } catch (error) {\n const authError = createAuthError(\n error instanceof Error ? error.message : 'Failed to check redirect result',\n 'REDIRECT_CHECK_FAILED',\n 'RedirectError',\n error,\n );\n handleSignInError(authError);\n }\n }, [ternSecure, handleSignInSuccess, handleSignInError, createAuthError]);\n\n const baseSignInUrl = ctxProps.path || ternSecureOptions.signInUrl;\n const baseSignUpUrl = ternSecureOptions.signUpUrl;\n\n const SignInUrl = buildURL(\n {\n base: baseSignInUrl,\n searchParams: currentParams,\n },\n { stringify: true, skipOrigin: false },\n ) as string;\n\n const SignUpUrl = buildURL(\n {\n base: baseSignUpUrl,\n searchParams: currentParams,\n },\n { stringify: true, skipOrigin: false },\n ) as string;\n\n const contextValue: SignInContextType = useMemo(\n () => ({\n handleSignInSuccess,\n handleSignInError,\n redirectAfterSignIn,\n checkRedirectResult,\n SignInUrl,\n SignUpUrl,\n onSuccess,\n }),\n [\n handleSignInSuccess,\n handleSignInError,\n redirectAfterSignIn,\n checkRedirectResult,\n SignInUrl,\n SignUpUrl,\n onSuccess,\n ],\n );\n\n return <SignInContext.Provider value={contextValue}>{children}</SignInContext.Provider>;\n}\n"],"mappings":"aA2JS,cAAAA,MAAA,oBAlJT,OAAS,YAAAC,MAAgB,oBACzB,OAAS,iBAAAC,MAAqB,4BAE9B,OAAS,iBAAAC,EAAe,eAAAC,EAAa,cAAAC,EAAY,WAAAC,MAAe,QAchE,MAAMC,EAAgBJ,EAAiC,CACrD,oBAAqB,IAAM,CAAC,EAC5B,kBAAmB,IAAM,CAAC,EAC1B,oBAAqB,IAAM,CAAC,EAC5B,UAAW,GACX,UAAW,GACX,oBAAqB,SAAY,CAAC,CACpC,CAAC,EAEYK,EAAmB,IAAMH,EAAWE,CAAa,EAMvD,SAASE,EAAe,CAC7B,SAAAC,EACA,UAAAC,EACA,iBAAAC,EACA,uBAAAC,EACA,uBAAAC,EACA,GAAGC,CACL,EAAwB,CACtB,MAAMC,EAAad,EAAc,EAC3Be,EAAoBD,EAAW,wBAAwB,EACvDE,EAAgBZ,EAAQ,IACxB,OAAO,OAAW,IACb,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAE5C,IAAI,gBACV,CAAC,CAAC,EAECa,EAAkBf,EACtB,CAACgB,EAAiBC,EAAcC,EAAe,YAAaC,IAAkC,CAC5F,MAAMC,EAAY,IAAI,MAAMJ,CAAO,EACnC,OAAAI,EAAU,KAAOF,EACjBE,EAAU,KAAOH,EACjBG,EAAU,SAAWD,EACdC,CACT,EACA,CAAC,CACH,EAEMC,EAAsBrB,EAAY,IAAM,CAC5CY,EAAW,oBAAoB,CACjC,EAAG,CAACA,CAAU,CAAC,EAETU,EAAsBtB,EAC1B,CAACuB,EAA8BC,IAAyC,CACtEjB,IAAYgB,GAAQ,IAAI,EACnBC,GAAS,cACZH,EAAoB,CAExB,EACA,CAACd,EAAWc,CAAmB,CACjC,EAEMI,EAAoBzB,EACvBoB,GAA6B,CAC5B,QAAQ,MAAMA,CAAS,CACzB,EACA,CAAC,CACH,EAEMM,EAAsB1B,EAAY,SAA2B,CACjE,GAAI,CACF,MAAM2B,EAAS,MAAMf,EAAW,kBAAkB,EAClD,GAAIe,GAAUA,EAAO,QACnBL,EAAoBK,EAAO,IAAI,UACtBA,GAAU,CAACA,EAAO,QAAS,CACpC,MAAMP,EAAYL,EAChBY,EAAO,SAAW,0BAClBA,EAAO,OAAS,kBAChB,gBACAA,CACF,EACAF,EAAkBL,CAAS,CAC7B,CACF,OAASQ,EAAO,CACd,MAAMR,EAAYL,EAChBa,aAAiB,MAAQA,EAAM,QAAU,kCACzC,wBACA,gBACAA,CACF,EACAH,EAAkBL,CAAS,CAC7B,CACF,EAAG,CAACR,EAAYU,EAAqBG,EAAmBV,CAAe,CAAC,EAElEc,EAAgBlB,EAAS,MAAQE,EAAkB,UACnDiB,EAAgBjB,EAAkB,UAElCkB,EAAYlC,EAChB,CACE,KAAMgC,EACN,aAAcf,CAChB,EACA,CAAE,UAAW,GAAM,WAAY,EAAM,CACvC,EAEMkB,EAAYnC,EAChB,CACE,KAAMiC,EACN,aAAchB,CAChB,EACA,CAAE,UAAW,GAAM,WAAY,EAAM,CACvC,EAEMmB,EAAkC/B,EACtC,KAAO,CACL,oBAAAoB,EACA,kBAAAG,EACA,oBAAAJ,EACA,oBAAAK,EACA,UAAAK,EACA,UAAAC,EACA,UAAAzB,CACF,GACA,CACEe,EACAG,EACAJ,EACAK,EACAK,EACAC,EACAzB,CACF,CACF,EAEA,OAAOX,EAACO,EAAc,SAAd,CAAuB,MAAO8B,EAAe,SAAA3B,EAAS,CAChE","names":["jsx","buildURL","useTernSecure","createContext","useCallback","useContext","useMemo","SignInContext","useSignInContext","SignInProvider","children","onSuccess","forceRedirectUrl","signInForceRedirectUrl","signUpForceRedirectUrl","ctxProps","ternSecure","ternSecureOptions","currentParams","createAuthError","message","code","name","response","authError","redirectAfterSignIn","handleSignInSuccess","user","options","handleSignInError","checkRedirectResult","result","error","baseSignInUrl","baseSignUpUrl","SignInUrl","SignUpUrl","contextValue"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var y=Object.create;var i=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,
|
|
1
|
+
"use strict";"use client";var y=Object.create;var i=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})},l=(t,e,s,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!k.call(t,n)&&n!==s&&i(t,n,{get:()=>e[n],enumerable:!(u=O(e,n))||u.enumerable});return t};var g=(t,e,s)=>(s=t!=null?y(E(t)):{},l(e||!t||!t.__esModule?i(s,"default",{value:t,enumerable:!0}):s,t)),w=t=>l(i({},"__esModule",{value:!0}),t);var N={};L(N,{TernSecureCtxProvider:()=>z});module.exports=w(N);var a=require("react/jsx-runtime"),T=require("@tern-secure/shared/derivedAuthState"),r=g(require("react")),c=require("../lib/isoTernSecureAuth"),m=require("./AuthProvider"),f=require("./IsomorphicTernSecureCtx");function z(t){const{children:e,initialState:s,instanceOptions:u}=t,{isoTernSecureAuth:n,instanceStatus:o}=M(u),[A,I]=(0,r.useState)({user:n.user,session:n.currentSession});r.default.useEffect(()=>n.addListener(h=>I({...h})),[]);const P=(0,T.deriveAuthState)(A,s),{token:S,email:d,user:p,userId:v}=P,x=(0,r.useMemo)(()=>({value:{userId:v,token:S,email:d,user:p}}),[v,S,d,p]),C=(0,r.useMemo)(()=>({value:n,instanceStatus:o}),[n,o]);return(0,a.jsx)(f.IsoTernSecureAuthCtx.Provider,{value:C,children:(0,a.jsx)(m.AuthProviderCtx.Provider,{value:x,children:e})})}const M=t=>{const e=(0,r.useMemo)(()=>c.IsoTernSecureAuth.getOrCreateInstance(t),[]),[s,u]=(0,r.useState)(e.status);return(0,r.useEffect)(()=>(e.on("status",u),()=>e.off("status",u)),[e]),(0,r.useEffect)(()=>{const n=e.addListener(o=>{console.warn("[useInitTernSecureAuth] Event received:",o)});return()=>n()},[e]),(0,r.useEffect)(()=>{e.initialize()},[e]),(0,r.useEffect)(()=>()=>{c.IsoTernSecureAuth.clearInstance()},[]),{isoTernSecureAuth:e,instanceStatus:s}};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 InitialState, type 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: InitialState | 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
|
|
1
|
+
{"version":3,"sources":["../../src/ctx/TernSecureCtxProvider.tsx"],"sourcesContent":["'use client';\n\nimport { deriveAuthState } from '@tern-secure/shared/derivedAuthState';\nimport { type InitialState, type 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: InitialState | 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 { token, email, user, userId } = derivedState;\n\n const authCtx = useMemo(() => {\n const value = {\n userId: userId,\n token: token,\n email: email,\n user: user,\n };\n return { value };\n }, [userId, token, email, user]);\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 const un = isoTernSecureAuth.addListener(event => {\n console.warn('[useInitTernSecureAuth] Event received:', event);\n });\n return () => un();\n }, [isoTernSecureAuth]);\n\n useEffect(() => {\n 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,GAwDM,IAAAI,EAAA,6BAtDNC,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,MAAAU,EAAO,MAAAC,EAAO,KAAAC,EAAM,OAAAC,CAAO,EAAIJ,EAEjCK,KAAU,WAAQ,KAOf,CAAE,MANK,CACZ,OAAQD,EACR,MAAOH,EACP,MAAOC,EACP,KAAMC,CACR,CACe,GACd,CAACC,EAAQH,EAAOC,EAAOC,CAAI,CAAC,EAEzBG,KAAc,WAClB,KAAO,CACL,MAAOb,EACP,eAAAC,CACF,GACA,CAACD,EAAUC,CAAc,CAC3B,EAEA,SACE,OAAC,uBAAqB,SAArB,CAA8B,MAAOY,EACpC,mBAAC,kBAAgB,SAAhB,CAAyB,MAAOD,EAAU,SAAAf,EAAS,EACtD,CAEJ,CAEA,MAAMK,EAAyBY,GAAsC,CACnE,MAAMC,KAAoB,WAAQ,IACzB,oBAAkB,oBAAoBD,CAAO,EACnD,CAAC,CAAC,EAEC,CAACb,EAAgBe,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,CACd,MAAME,EAAKF,EAAkB,YAAYG,GAAS,CAChD,QAAQ,KAAK,0CAA2CA,CAAK,CAC/D,CAAC,EACD,MAAO,IAAMD,EAAG,CAClB,EAAG,CAACF,CAAiB,CAAC,KAEtB,aAAU,IAAM,CACdA,EAAkB,WAAW,CAC/B,EAAG,CAACA,CAAiB,CAAC,KAEtB,aAAU,IACD,IAAM,CACX,oBAAkB,cAAc,CAClC,EACC,CAAC,CAAC,EAEE,CACL,kBAAAA,EACA,eAAAd,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","token","email","user","userId","authCtx","ternAuthCtx","options","isoTernSecureAuth","setInstanceStatus","un","event"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsx as l}from"react/jsx-runtime";import{deriveAuthState as P}from"@tern-secure/shared/derivedAuthState";import x,{useEffect as s,useMemo as i,useState as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{deriveAuthState as P}from"@tern-secure/shared/derivedAuthState";import x,{useEffect as s,useMemo as i,useState as v}from"react";import{IsoTernSecureAuth as h}from"../lib/isoTernSecureAuth";import{AuthProviderCtx as C}from"./AuthProvider";import{IsoTernSecureAuthCtx as y}from"./IsomorphicTernSecureCtx";function z(u){const{children:e,initialState:o,instanceOptions:r}=u,{isoTernSecureAuth:t,instanceStatus:n}=O(r),[T,m]=v({user:t.user,session:t.currentSession});x.useEffect(()=>t.addListener(p=>m({...p})),[]);const f=P(T,o),{token:c,email:a,user:S,userId:d}=f,A=i(()=>({value:{userId:d,token:c,email:a,user:S}}),[d,c,a,S]),I=i(()=>({value:t,instanceStatus:n}),[t,n]);return l(y.Provider,{value:I,children:l(C.Provider,{value:A,children:e})})}const O=u=>{const e=i(()=>h.getOrCreateInstance(u),[]),[o,r]=v(e.status);return s(()=>(e.on("status",r),()=>e.off("status",r)),[e]),s(()=>{const t=e.addListener(n=>{console.warn("[useInitTernSecureAuth] Event received:",n)});return()=>t()},[e]),s(()=>{e.initialize()},[e]),s(()=>()=>{h.clearInstance()},[]),{isoTernSecureAuth:e,instanceStatus:o}};export{z 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 InitialState, type 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: InitialState | 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
|
|
1
|
+
{"version":3,"sources":["../../src/ctx/TernSecureCtxProvider.tsx"],"sourcesContent":["'use client';\n\nimport { deriveAuthState } from '@tern-secure/shared/derivedAuthState';\nimport { type InitialState, type 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: InitialState | 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 { token, email, user, userId } = derivedState;\n\n const authCtx = useMemo(() => {\n const value = {\n userId: userId,\n token: token,\n email: email,\n user: user,\n };\n return { value };\n }, [userId, token, email, user]);\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 const un = isoTernSecureAuth.addListener(event => {\n console.warn('[useInitTernSecureAuth] Event received:', event);\n });\n return () => un();\n }, [isoTernSecureAuth]);\n\n useEffect(() => {\n 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":"aAwDM,cAAAA,MAAA,oBAtDN,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,MAAAS,EAAO,MAAAC,EAAO,KAAAC,EAAM,OAAAC,CAAO,EAAIJ,EAEjCK,EAAUrB,EAAQ,KAOf,CAAE,MANK,CACZ,OAAQoB,EACR,MAAOH,EACP,MAAOC,EACP,KAAMC,CACR,CACe,GACd,CAACC,EAAQH,EAAOC,EAAOC,CAAI,CAAC,EAEzBG,EAActB,EAClB,KAAO,CACL,MAAOU,EACP,eAAAC,CACF,GACA,CAACD,EAAUC,CAAc,CAC3B,EAEA,OACEf,EAACQ,EAAqB,SAArB,CAA8B,MAAOkB,EACpC,SAAA1B,EAACO,EAAgB,SAAhB,CAAyB,MAAOkB,EAAU,SAAAd,EAAS,EACtD,CAEJ,CAEA,MAAMK,EAAyBW,GAAsC,CACnE,MAAMC,EAAoBxB,EAAQ,IACzBE,EAAkB,oBAAoBqB,CAAO,EACnD,CAAC,CAAC,EAEC,CAACZ,EAAgBc,CAAiB,EAAIxB,EAASuB,EAAkB,MAAM,EAE7E,OAAAzB,EAAU,KACHyB,EAAkB,GAAG,SAAUC,CAAiB,EAC9C,IAAMD,EAAkB,IAAI,SAAUC,CAAiB,GAC7D,CAACD,CAAiB,CAAC,EAEtBzB,EAAU,IAAM,CACd,MAAM2B,EAAKF,EAAkB,YAAYG,GAAS,CAChD,QAAQ,KAAK,0CAA2CA,CAAK,CAC/D,CAAC,EACD,MAAO,IAAMD,EAAG,CAClB,EAAG,CAACF,CAAiB,CAAC,EAEtBzB,EAAU,IAAM,CACdyB,EAAkB,WAAW,CAC/B,EAAG,CAACA,CAAiB,CAAC,EAEtBzB,EAAU,IACD,IAAM,CACXG,EAAkB,cAAc,CAClC,EACC,CAAC,CAAC,EAEE,CACL,kBAAAsB,EACA,eAAAb,CACF,CACF","names":["jsx","deriveAuthState","React","useEffect","useMemo","useState","IsoTernSecureAuth","AuthProviderCtx","IsoTernSecureAuthCtx","TernSecureCtxProvider","props","children","initialState","instanceOptions","instance","instanceStatus","useInitTernSecureAuth","authState","setAuthState","e","derivedState","token","email","user","userId","authCtx","ternAuthCtx","options","isoTernSecureAuth","setInstanceStatus","un","event"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UseSignInReturn,
|
|
1
|
+
import { UseSignInReturn, SignInFormValues, SignInResponse, ResendEmailVerification } from '@tern-secure/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Hook to access the SignInResource methods from TernSecureAuth
|
|
@@ -6,12 +6,12 @@ import { UseSignInReturn, SignInFormValuesTree, SignInResponseTree, ResendEmailV
|
|
|
6
6
|
*/
|
|
7
7
|
declare const useSignIn: () => UseSignInReturn;
|
|
8
8
|
declare const signIn: {
|
|
9
|
-
withEmailAndPassword: (params:
|
|
9
|
+
withEmailAndPassword: (params: SignInFormValues) => Promise<SignInResponse>;
|
|
10
10
|
withSocialProvider: (provider: string, options?: {
|
|
11
11
|
mode?: "popup" | "redirect";
|
|
12
|
-
}) => Promise<
|
|
12
|
+
}) => Promise<SignInResponse | void>;
|
|
13
13
|
resendEmailVerification: () => Promise<ResendEmailVerification>;
|
|
14
|
-
checkRedirectResult: () => Promise<
|
|
14
|
+
checkRedirectResult: () => Promise<SignInResponse | null>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export { signIn, useSignIn };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UseSignInReturn,
|
|
1
|
+
import { UseSignInReturn, SignInFormValues, SignInResponse, ResendEmailVerification } from '@tern-secure/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Hook to access the SignInResource methods from TernSecureAuth
|
|
@@ -6,12 +6,12 @@ import { UseSignInReturn, SignInFormValuesTree, SignInResponseTree, ResendEmailV
|
|
|
6
6
|
*/
|
|
7
7
|
declare const useSignIn: () => UseSignInReturn;
|
|
8
8
|
declare const signIn: {
|
|
9
|
-
withEmailAndPassword: (params:
|
|
9
|
+
withEmailAndPassword: (params: SignInFormValues) => Promise<SignInResponse>;
|
|
10
10
|
withSocialProvider: (provider: string, options?: {
|
|
11
11
|
mode?: "popup" | "redirect";
|
|
12
|
-
}) => Promise<
|
|
12
|
+
}) => Promise<SignInResponse | void>;
|
|
13
13
|
resendEmailVerification: () => Promise<ResendEmailVerification>;
|
|
14
|
-
checkRedirectResult: () => Promise<
|
|
14
|
+
checkRedirectResult: () => Promise<SignInResponse | null>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export { signIn, useSignIn };
|
package/dist/hooks/useSignIn.js
CHANGED
|
@@ -1,2 +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
|
|
1
|
+
"use strict";"use client";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(n,e)=>{for(var i in e)o(n,i,{get:e[i],enumerable:!0})},h=(n,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of d(e))!l.call(n,r)&&r!==i&&o(n,r,{get:()=>e[r],enumerable:!(s=u(e,r))||s.enumerable});return n};var m=n=>h(o({},"__esModule",{value:!0}),n);var S={};c(S,{signIn:()=>I,useSignIn:()=>g});module.exports=m(S);var t=require("../ctx/TernSecureAuthResourcesCtx"),a=require("./useAssertWrappedTernSecureProvider");const g=()=>{(0,a.useAssertWrappedByTernSecureAuthProvider)("useSignIn");const n=(0,t.useAuthSignInCtx)();return n?{isLoaded:!0,signIn:n}:{isLoaded:!1,signIn:void 0}},I={withEmailAndPassword:async n=>{const e=(0,t.useAuthSignInCtx)();if(!e)throw new Error("SignIn methods not available - auth not initialized");return e.withEmailAndPassword(n)},withSocialProvider:async(n,e)=>{const i=(0,t.useAuthSignInCtx)();if(!i)throw new Error("SignIn methods not available - auth not initialized");return i.withSocialProvider(n,e)},resendEmailVerification:async()=>{const n=(0,t.useAuthSignInCtx)();if(!n)throw new Error("SignIn methods not available - auth not initialized");return n.resendEmailVerification()},checkRedirectResult:async()=>{const n=(0,t.useAuthSignInCtx)();if(!n)throw new Error("SignIn methods not available - auth not initialized");return n.checkRedirectResult()}};0&&(module.exports={signIn,useSignIn});
|
|
2
2
|
//# sourceMappingURL=useSignIn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useSignIn.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ResendEmailVerification,\n
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useSignIn.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ResendEmailVerification,\n SignInFormValues,\n SignInResponse,\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: SignInFormValues\n ): Promise<SignInResponse> => {\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<SignInResponse | 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<SignInResponse | 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,GAC4B,CAC5B,MAAMD,KAAO,oBAAiB,EAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,qBAAqBC,CAAM,CACzC,EAEA,mBAAoB,MAClBC,EACAC,IACmC,CACnC,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,SAA4C,CAC/D,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"]}
|
package/dist/hooks/useSignIn.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useAuthSignInCtx as
|
|
1
|
+
"use client";import{useAuthSignInCtx as e}from"../ctx/TernSecureAuthResourcesCtx";import{useAssertWrappedByTernSecureAuthProvider as r}from"./useAssertWrappedTernSecureProvider";const a=()=>{r("useSignIn");const n=e();return n?{isLoaded:!0,signIn:n}:{isLoaded:!1,signIn:void 0}},u={withEmailAndPassword:async n=>{const i=e();if(!i)throw new Error("SignIn methods not available - auth not initialized");return i.withEmailAndPassword(n)},withSocialProvider:async(n,i)=>{const t=e();if(!t)throw new Error("SignIn methods not available - auth not initialized");return t.withSocialProvider(n,i)},resendEmailVerification:async()=>{const n=e();if(!n)throw new Error("SignIn methods not available - auth not initialized");return n.resendEmailVerification()},checkRedirectResult:async()=>{const n=e();if(!n)throw new Error("SignIn methods not available - auth not initialized");return n.checkRedirectResult()}};export{u as signIn,a as useSignIn};
|
|
2
2
|
//# sourceMappingURL=useSignIn.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useSignIn.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ResendEmailVerification,\n
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useSignIn.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ResendEmailVerification,\n SignInFormValues,\n SignInResponse,\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: SignInFormValues\n ): Promise<SignInResponse> => {\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<SignInResponse | 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<SignInResponse | 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,GAC4B,CAC5B,MAAMF,EAAOH,EAAiB,EAC9B,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,EAAK,qBAAqBE,CAAM,CACzC,EAEA,mBAAoB,MAClBC,EACAC,IACmC,CACnC,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,SAA4C,CAC/D,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
|
@@ -4,10 +4,12 @@ export { useSession } from './hooks/useSession.mjs';
|
|
|
4
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
|
+
export { SignInProvider, useSignInContext } from './ctx/SignInCtx.mjs';
|
|
7
8
|
export { handleInternalRoute, isAuthRoute, isBaseAuthRoute, isInternalRoute } from './route-handler/internal-route.mjs';
|
|
8
9
|
export { cn } from './lib/utils.mjs';
|
|
9
10
|
export { Browser, IsoTernSecureAuthOptions, IsomorphicTernSecureOptions, TernSecureProviderProps } from './types.mjs';
|
|
10
11
|
import '@tern-secure/types';
|
|
11
12
|
import 'react/jsx-runtime';
|
|
12
13
|
import 'react';
|
|
14
|
+
import '@tern-secure/auth';
|
|
13
15
|
import 'clsx';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ export { useSession } from './hooks/useSession.js';
|
|
|
4
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
|
+
export { SignInProvider, useSignInContext } from './ctx/SignInCtx.js';
|
|
7
8
|
export { handleInternalRoute, isAuthRoute, isBaseAuthRoute, isInternalRoute } from './route-handler/internal-route.js';
|
|
8
9
|
export { cn } from './lib/utils.js';
|
|
9
10
|
export { Browser, IsoTernSecureAuthOptions, IsomorphicTernSecureOptions, TernSecureProviderProps } from './types.js';
|
|
10
11
|
import '@tern-secure/types';
|
|
11
12
|
import 'react/jsx-runtime';
|
|
12
13
|
import 'react';
|
|
14
|
+
import '@tern-secure/auth';
|
|
13
15
|
import 'clsx';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var P=(o,e)=>{for(var n in e)p(o,n,{get:e[n],enumerable:!0})},a=(o,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of h(e))!T.call(o,t)&&t!==n&&p(o,t,{get:()=>e[t],enumerable:!(i=d(e,t))||i.enumerable});return o};var g=o=>a(p({},"__esModule",{value:!0}),o);var v={};P(v,{SignInProvider:()=>u.SignInProvider,TernSecureCtxProvider:()=>I.TernSecureCtxProvider,TernSecureProvider:()=>S.TernSecureProvider,cn:()=>c.cn,handleInternalRoute:()=>r.handleInternalRoute,isAuthRoute:()=>r.isAuthRoute,isBaseAuthRoute:()=>r.isBaseAuthRoute,isInternalRoute:()=>r.isInternalRoute,signIn:()=>s.signIn,useAuth:()=>x.useAuth,useIdToken:()=>m.useIdToken,useSession:()=>f.useSession,useSignIn:()=>s.useSignIn,useSignInContext:()=>u.useSignInContext});module.exports=g(v);var x=require("./hooks/useAuth"),m=require("./hooks/useIdToken"),f=require("./hooks/useSession"),s=require("./hooks/useSignIn"),I=require("./ctx/TernSecureCtxProvider"),S=require("./ctx/TernSecureProvider"),u=require("./ctx/SignInCtx"),r=require("./route-handler/internal-route"),c=require("./lib/utils");0&&(module.exports={SignInProvider,TernSecureCtxProvider,TernSecureProvider,cn,handleInternalRoute,isAuthRoute,isBaseAuthRoute,isInternalRoute,signIn,useAuth,useIdToken,useSession,useSignIn,useSignInContext});
|
|
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
|
|
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 { TernSecureCtxProvider } from './ctx/TernSecureCtxProvider';\nexport { TernSecureProvider } from './ctx/TernSecureProvider';\nexport { useSignInContext, SignInProvider } from './ctx/SignInCtx';\n\nexport {\n isAuthRoute,\n isBaseAuthRoute,\n isInternalRoute,\n handleInternalRoute,\n} from './route-handler/internal-route';\n\nexport { cn } from './lib/utils';\n\nexport type {\n IsomorphicTernSecureOptions,\n IsoTernSecureAuthOptions,\n Browser,\n TernSecureProviderProps,\n} from './types';\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4dAAAE,EAAAF,GAAA,IAAAG,EAAwB,2BACxBC,EAA2B,8BAC3BC,EAA2B,8BAC3BC,EAAkC,6BAClCC,EAAsC,uCACtCC,EAAmC,oCACnCC,EAAiD,2BAEjDC,EAKO,0CAEPC,EAAmB","names":["index_exports","__export","__toCommonJS","import_useAuth","import_useIdToken","import_useSession","import_useSignIn","import_TernSecureCtxProvider","import_TernSecureProvider","import_SignInCtx","import_internal_route","import_utils"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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
|
|
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 x}from"./hooks/useSignIn";import{TernSecureCtxProvider as f}from"./ctx/TernSecureCtxProvider";import{TernSecureProvider as S}from"./ctx/TernSecureProvider";import{useSignInContext as d,SignInProvider as h}from"./ctx/SignInCtx";import{isAuthRoute as P,isBaseAuthRoute as a,isInternalRoute as g,handleInternalRoute as v}from"./route-handler/internal-route";import{cn as R}from"./lib/utils";export{h as SignInProvider,f as TernSecureCtxProvider,S as TernSecureProvider,R as cn,v as handleInternalRoute,P as isAuthRoute,a as isBaseAuthRoute,g as isInternalRoute,x as signIn,o as useAuth,n as useIdToken,u as useSession,i as useSignIn,d as useSignInContext};
|
|
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
|
|
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 { TernSecureCtxProvider } from './ctx/TernSecureCtxProvider';\nexport { TernSecureProvider } from './ctx/TernSecureProvider';\nexport { useSignInContext, SignInProvider } from './ctx/SignInCtx';\n\nexport {\n isAuthRoute,\n isBaseAuthRoute,\n isInternalRoute,\n handleInternalRoute,\n} from './route-handler/internal-route';\n\nexport { cn } from './lib/utils';\n\nexport type {\n IsomorphicTernSecureOptions,\n IsoTernSecureAuthOptions,\n Browser,\n TernSecureProviderProps,\n} from './types';\n"],"mappings":"AAAA,OAAS,WAAAA,MAAe,kBACxB,OAAS,cAAAC,MAAkB,qBAC3B,OAAS,cAAAC,MAAkB,qBAC3B,OAAS,aAAAC,EAAW,UAAAC,MAAc,oBAClC,OAAS,yBAAAC,MAA6B,8BACtC,OAAS,sBAAAC,MAA0B,2BACnC,OAAS,oBAAAC,EAAkB,kBAAAC,MAAsB,kBAEjD,OACE,eAAAC,EACA,mBAAAC,EACA,mBAAAC,EACA,uBAAAC,MACK,iCAEP,OAAS,MAAAC,MAAU","names":["useAuth","useIdToken","useSession","useSignIn","signIn","TernSecureCtxProvider","TernSecureProvider","useSignInContext","SignInProvider","isAuthRoute","isBaseAuthRoute","isInternalRoute","handleInternalRoute","cn"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
|
-
import { TernSecureAuth, TernSecureAuthStatus, SignInResource, SignUpResource, ListenerCallback, UnsubscribeCallback, SignOutOptions, SignedInSession } from '@tern-secure/types';
|
|
2
|
+
import { TernSecureAuth, TernSecureAuthStatus, SignInResource, SignUpResource, TernSecureAuthOptions, ListenerCallback, UnsubscribeCallback, SignOutOptions, SignedInSession, SignInRedirectOptions, SignUpRedirectOptions } from '@tern-secure/types';
|
|
3
3
|
import { IsoTernSecureAuthOptions } from '../types.mjs';
|
|
4
4
|
|
|
5
5
|
declare function inBrowser(): boolean;
|
|
@@ -27,6 +27,14 @@ declare class IsoTernSecureAuth implements TernSecureAuth {
|
|
|
27
27
|
get domain(): string;
|
|
28
28
|
get proxyUrl(): string;
|
|
29
29
|
get mode(): 'browser' | 'server';
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
_internal_getOption<K extends keyof TernSecureAuthOptions>(key: K): TernSecureAuthOptions[K] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
_internal_getAllOptions(): Readonly<TernSecureAuthOptions>;
|
|
30
38
|
constructor(options: IsoTernSecureAuthOptions);
|
|
31
39
|
get sdkMetadata(): _tern_secure_types.TernAuthSDK | undefined;
|
|
32
40
|
get version(): string | undefined;
|
|
@@ -40,6 +48,11 @@ declare class IsoTernSecureAuth implements TernSecureAuth {
|
|
|
40
48
|
signOut: (options?: SignOutOptions) => Promise<void>;
|
|
41
49
|
get currentSession(): SignedInSession | null;
|
|
42
50
|
onAuthStateChanged(callback: (user: any) => void): () => void;
|
|
51
|
+
getRedirectResult: () => Promise<any>;
|
|
52
|
+
redirectToSignIn: (options?: SignInRedirectOptions) => Promise<void>;
|
|
53
|
+
redirectToSignUp: (options?: SignUpRedirectOptions) => Promise<void>;
|
|
54
|
+
redirectAfterSignIn: (redirectUrl?: string) => void;
|
|
55
|
+
redirectAfterSignUp: (redirectUrl?: string) => void;
|
|
43
56
|
initialize: () => Promise<void>;
|
|
44
57
|
}
|
|
45
58
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
|
-
import { TernSecureAuth, TernSecureAuthStatus, SignInResource, SignUpResource, ListenerCallback, UnsubscribeCallback, SignOutOptions, SignedInSession } from '@tern-secure/types';
|
|
2
|
+
import { TernSecureAuth, TernSecureAuthStatus, SignInResource, SignUpResource, TernSecureAuthOptions, ListenerCallback, UnsubscribeCallback, SignOutOptions, SignedInSession, SignInRedirectOptions, SignUpRedirectOptions } from '@tern-secure/types';
|
|
3
3
|
import { IsoTernSecureAuthOptions } from '../types.js';
|
|
4
4
|
|
|
5
5
|
declare function inBrowser(): boolean;
|
|
@@ -27,6 +27,14 @@ declare class IsoTernSecureAuth implements TernSecureAuth {
|
|
|
27
27
|
get domain(): string;
|
|
28
28
|
get proxyUrl(): string;
|
|
29
29
|
get mode(): 'browser' | 'server';
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
_internal_getOption<K extends keyof TernSecureAuthOptions>(key: K): TernSecureAuthOptions[K] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
_internal_getAllOptions(): Readonly<TernSecureAuthOptions>;
|
|
30
38
|
constructor(options: IsoTernSecureAuthOptions);
|
|
31
39
|
get sdkMetadata(): _tern_secure_types.TernAuthSDK | undefined;
|
|
32
40
|
get version(): string | undefined;
|
|
@@ -40,6 +48,11 @@ declare class IsoTernSecureAuth implements TernSecureAuth {
|
|
|
40
48
|
signOut: (options?: SignOutOptions) => Promise<void>;
|
|
41
49
|
get currentSession(): SignedInSession | null;
|
|
42
50
|
onAuthStateChanged(callback: (user: any) => void): () => void;
|
|
51
|
+
getRedirectResult: () => Promise<any>;
|
|
52
|
+
redirectToSignIn: (options?: SignInRedirectOptions) => Promise<void>;
|
|
53
|
+
redirectToSignUp: (options?: SignUpRedirectOptions) => Promise<void>;
|
|
54
|
+
redirectAfterSignIn: (redirectUrl?: string) => void;
|
|
55
|
+
redirectAfterSignUp: (redirectUrl?: string) => void;
|
|
43
56
|
initialize: () => Promise<void>;
|
|
44
57
|
}
|
|
45
58
|
|
|
@@ -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
|
|
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.v20251008165428",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}_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),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"),()=>{})}getRedirectResult=async()=>{if(!this.ternauth?.getRedirectResult)throw new Error("TernSecure instance not initialized");return this.ternauth.getRedirectResult()};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()=>{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 +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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,cAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAqD,6BACrDC,EAAmD,+CACnDC,EAAgC,qCAehC,MAAMC,EAAe,CACnB,KAAM,qBACN,QAAS,+BACT,YAAa,QAAQ,IAAI,QAC3B,EAEO,SAASL,GAAqB,CACnC,OAAO,OAAO,OAAW,GAC3B,CAMO,MAAMD,CAA4C,CACtC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N,oFACF,EACA,KAAKZ,GAAU,QACf,KAAKI,GAAU,KAAK,aAAW,OAAQ,OAAO,GAGzC,KAAK,QACd,EAEO,GAA2B,IAAIS,IAChC,KAAK,UAAU,GACV,KAAK,SAAS,GAAG,GAAGA,CAAI,EAExB,KAAKT,GAAU,GAAG,GAAGS,CAAI,EAI7B,IAA6B,IAAIA,IAClC,KAAK,UAAU,IACV,KAAK,SAAS,IAAI,GAAGA,CAAI,EAEzB,KAAKT,GAAU,IAAI,GAAGS,CAAI,EAIrC,YAAeD,GAAoD,CACjE,GAAI,KAAK,SACP,OAAO,KAAK,SAAS,YAAYA,CAAQ,EACpC,CACL,MAAME,EAAc,IAAM,CACxB,MAAMH,EAAmB,KAAK,eAAe,IAAIC,CAAQ,EACrDD,IACFA,EAAiB,YAAY,EAC7B,KAAK,eAAe,OAAOC,CAAQ,EAEvC,EACA,YAAK,eAAe,IAAIA,EAAU,CAAE,YAAAE,CAAY,CAAC,EAC1CA,CACT,CACF,EAEA,QAAU,MAAOR,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,mBAAmBS,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":["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"]}
|
|
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 SignInRedirectOptions,\n SignInResource,\n SignOutOptions,\n SignUpRedirectOptions,\n SignUpResource,\n TernSecureAuth,\n TernSecureAuthOptions,\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 /**\n * @internal\n */\n public _internal_getOption<K extends keyof TernSecureAuthOptions>(key: K): TernSecureAuthOptions[K] | undefined {\n return this.ternauth?._internal_getOption ? this.ternauth?._internal_getOption(key) : this.options[key];\n }\n\n /** \n * @internal\n */\n public _internal_getAllOptions(): Readonly<TernSecureAuthOptions> {\n return Object.freeze({ ...this.options });\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 getRedirectResult = async (): Promise<any> => {\n if (!this.ternauth?.getRedirectResult) {\n throw new Error('TernSecure instance not initialized');\n }\n return this.ternauth.getRedirectResult();\n };\n\n redirectToSignIn = async (options?: SignInRedirectOptions) => {\n if (this.ternauth?.redirectToSignIn) {\n this.ternauth.redirectToSignIn(options);\n }\n };\n\n redirectToSignUp = async (options?: SignUpRedirectOptions) => {\n if (this.ternauth?.redirectToSignUp) {\n this.ternauth.redirectToSignUp();\n }\n };\n\n redirectAfterSignIn = (redirectUrl?: string): void => {\n if (this.ternauth?.redirectAfterSignIn) {\n this.ternauth.redirectAfterSignIn();\n }\n }\n\n redirectAfterSignUp = (redirectUrl?: string): void => {\n if (this.ternauth?.redirectAfterSignUp) {\n this.ternauth.redirectAfterSignUp();\n }\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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,cAAAC,IAAA,eAAAC,EAAAJ,GAAA,IA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AAK,SAMH,KAAK,SAAS,mBAAmBA,CAAQ,GAL9C,QAAQ,KACN,iFACF,EACO,IAAM,CAAC,EAGlB,CAEA,kBAAoB,SAA0B,CAC5C,GAAI,CAAC,KAAK,UAAU,kBAClB,MAAM,IAAI,MAAM,qCAAqC,EAEvD,OAAO,KAAK,SAAS,kBAAkB,CACzC,EAEA,iBAAmB,MAAOV,GAAoC,CACxD,KAAK,UAAU,kBACjB,KAAK,SAAS,iBAAiBA,CAAO,CAE1C,EAEA,iBAAmB,MAAOA,GAAoC,CACxD,KAAK,UAAU,kBACjB,KAAK,SAAS,iBAAiB,CAEnC,EAEA,oBAAuBW,GAA+B,CAChD,KAAK,UAAU,qBACjB,KAAK,SAAS,oBAAoB,CAEtC,EAEA,oBAAuBA,GAA+B,CAChD,KAAK,UAAU,qBACjB,KAAK,SAAS,oBAAoB,CAEtC,EAEAC,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","key","TernSecureAuth","tern","TernSecureAuthImpl","ternauth","listenerHandlers","listener","args","unsubscribe","callback","redirectUrl","#awaitForTernSecureAuth","resolve","error"]}
|
|
@@ -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.v20251008165428",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}_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),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"),()=>{})}getRedirectResult=async()=>{if(!this.ternauth?.getRedirectResult)throw new Error("TernSecure instance not initialized");return this.ternauth.getRedirectResult()};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()=>{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
|
|
@@ -1 +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,+BACT,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,EAAmC,CAC5D,OACE,CAACR,EAAU,GACX,CAAC,KAAKO,IACLC,EAAQ,gBAAkB,KAAKD,GAAU,iB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K,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"]}
|
|
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 SignInRedirectOptions,\n SignInResource,\n SignOutOptions,\n SignUpRedirectOptions,\n SignUpResource,\n TernSecureAuth,\n TernSecureAuthOptions,\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 /**\n * @internal\n */\n public _internal_getOption<K extends keyof TernSecureAuthOptions>(key: K): TernSecureAuthOptions[K] | undefined {\n return this.ternauth?._internal_getOption ? this.ternauth?._internal_getOption(key) : this.options[key];\n }\n\n /** \n * @internal\n */\n public _internal_getAllOptions(): Readonly<TernSecureAuthOptions> {\n return Object.freeze({ ...this.options });\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 getRedirectResult = async (): Promise<any> => {\n if (!this.ternauth?.getRedirectResult) {\n throw new Error('TernSecure instance not initialized');\n }\n return this.ternauth.getRedirectResult();\n };\n\n redirectToSignIn = async (options?: SignInRedirectOptions) => {\n if (this.ternauth?.redirectToSignIn) {\n this.ternauth.redirectToSignIn(options);\n }\n };\n\n redirectToSignUp = async (options?: SignUpRedirectOptions) => {\n if (this.ternauth?.redirectToSignUp) {\n this.ternauth.redirectToSignUp();\n }\n };\n\n redirectAfterSignIn = (redirectUrl?: string): void => {\n if (this.ternauth?.redirectAfterSignIn) {\n this.ternauth.redirectAfterSignIn();\n }\n }\n\n redirectAfterSignUp = (redirectUrl?: string): void => {\n if (this.ternauth?.redirectAfterSignUp) {\n this.ternauth.redirectAfterSignUp();\n }\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,4BAkBhC,MAAMC,EAAe,CACnB,KAAM,qBACN,QAAS,+BACT,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,O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uthImpl","createTernAuthEventBus","ternEvents","handleValueOrFn","SDK_METADATA","inBrowser","IsoTernSecureAuth","#status","#apiUrl","#domain","#proxyUrl","#eventBus","#instance","options","key","TernSecureAuth","tern","ternauth","listenerHandlers","listener","args","unsubscribe","callback","redirectUrl","#awaitForTernSecureAuth","resolve","error"]}
|
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.v20251008165428",
|
|
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.v20251008165428",
|
|
40
|
+
"@tern-secure/shared": "1.3.0-canary.v20251008165428",
|
|
41
|
+
"@tern-secure/types": "1.1.0-canary.v20251008165428"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tailwindcss/cli": "^4.1.6",
|