@tern-secure/nextjs 3.1.55 → 3.1.57

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.
Files changed (37) hide show
  1. package/dist/cjs/app-router/client/TernSecureProvider.cjs +69 -22
  2. package/dist/cjs/app-router/client/TernSecureProvider.cjs.map +1 -1
  3. package/dist/cjs/app-router/server/TernSecureServerProvider.cjs +89 -27
  4. package/dist/cjs/app-router/server/TernSecureServerProvider.cjs.map +1 -1
  5. package/dist/cjs/boundary/TernSecureCtx.cjs +32 -5
  6. package/dist/cjs/boundary/TernSecureCtx.cjs.map +1 -1
  7. package/dist/cjs/boundary/hooks/use-auth.cjs +26 -11
  8. package/dist/cjs/boundary/hooks/use-auth.cjs.map +1 -1
  9. package/dist/cjs/index.cjs +113 -45
  10. package/dist/cjs/index.cjs.map +1 -1
  11. package/dist/esm/app-router/client/TernSecureProvider.d.ts +12 -1
  12. package/dist/esm/app-router/client/TernSecureProvider.js +67 -3
  13. package/dist/esm/app-router/client/TernSecureProvider.js.map +1 -1
  14. package/dist/esm/app-router/server/TernSecureServerProvider.d.ts +9 -6
  15. package/dist/esm/app-router/server/TernSecureServerProvider.js +1 -1
  16. package/dist/esm/boundary/TernSecureCtx.d.ts +19 -12
  17. package/dist/esm/boundary/TernSecureCtx.js +1 -1
  18. package/dist/esm/boundary/hooks/use-auth.d.ts +23 -8
  19. package/dist/esm/boundary/hooks/use-auth.js +2 -2
  20. package/dist/esm/chunk-32DZLLHE.js +43 -0
  21. package/dist/esm/chunk-32DZLLHE.js.map +1 -0
  22. package/dist/esm/chunk-FMHBRXHR.js +20 -0
  23. package/dist/esm/chunk-FMHBRXHR.js.map +1 -0
  24. package/dist/esm/chunk-S2ODB3YJ.js +31 -0
  25. package/dist/esm/chunk-S2ODB3YJ.js.map +1 -0
  26. package/dist/esm/index.d.ts +8 -5
  27. package/dist/esm/index.js +8 -4
  28. package/dist/esm/index.js.map +1 -1
  29. package/package.json +2 -3
  30. package/dist/esm/chunk-5JJ6CT72.js +0 -20
  31. package/dist/esm/chunk-5JJ6CT72.js.map +0 -1
  32. package/dist/esm/chunk-6NBIYUE5.js +0 -16
  33. package/dist/esm/chunk-6NBIYUE5.js.map +0 -1
  34. package/dist/esm/chunk-I2PGODCQ.js +0 -17
  35. package/dist/esm/chunk-I2PGODCQ.js.map +0 -1
  36. package/dist/esm/chunk-QYWR3ALC.js +0 -40
  37. package/dist/esm/chunk-QYWR3ALC.js.map +0 -1
@@ -62,13 +62,34 @@ auth$1.setPersistence(auth, auth$1.browserSessionPersistence);
62
62
  firestore.getFirestore(clientApp);
63
63
  storage.getStorage(clientApp);
64
64
  var TernSecureAuth = () => auth;
65
- var TernSecureContext = React__default.default.createContext(void 0);
66
- var TernSecureCtxProvider = (props) => {
67
- const { children, options } = props;
68
- return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { value: options }, children });
65
+ var TernSecureError = class extends Error {
66
+ constructor(message) {
67
+ super(`[TernSecure] ${message}`);
68
+ this.name = "TernSecureError";
69
+ }
70
+ };
71
+ var TernSecureContext = React__default.default.createContext(null);
72
+ TernSecureContext.displayName = "TernSecureContext";
73
+ var TernSecureCtxProvider = ({
74
+ children
75
+ }) => {
76
+ if (typeof window === "undefined") {
77
+ throw new TernSecureError(
78
+ "TernSecureCtxProvider must be used in client components"
79
+ );
80
+ }
81
+ if (process.env.NODE_ENV !== "production") {
82
+ React__default.default.useEffect(() => {
83
+ console.log("[TernSecure] Provider initialized in client component");
84
+ }, []);
85
+ }
86
+ return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { dynamic: true }, children });
69
87
  };
70
88
  var auth2 = TernSecureAuth();
71
89
  function TernSecureClientProvider({ children }) {
90
+ if (typeof window === "undefined") {
91
+ throw new TernSecureError("TernSecureClientProvider must be used in client components");
92
+ }
72
93
  const [authState, setAuthState] = React.useState({
73
94
  loading: true,
74
95
  isSignedIn: false,
@@ -76,26 +97,52 @@ function TernSecureClientProvider({ children }) {
76
97
  error: null
77
98
  });
78
99
  React__default.default.useEffect(() => {
79
- const unsubscribe = auth$1.onAuthStateChanged(auth2, (user) => {
80
- if (user) {
81
- setAuthState({
82
- loading: false,
83
- isSignedIn: true,
84
- userId: user.uid,
85
- error: null
86
- });
87
- } else {
88
- setAuthState({
89
- loading: false,
90
- isSignedIn: false,
91
- userId: null,
92
- error: null
93
- });
100
+ if (process.env.NODE_ENV !== "production") {
101
+ console.log("[TernSecure] Initializing auth state listener");
102
+ }
103
+ try {
104
+ const unsubscribe = auth$1.onAuthStateChanged(
105
+ auth2,
106
+ (user) => {
107
+ setAuthState({
108
+ loading: false,
109
+ isSignedIn: !!user,
110
+ userId: user?.uid || null,
111
+ error: null
112
+ });
113
+ },
114
+ (error) => {
115
+ setAuthState((prev) => ({
116
+ ...prev,
117
+ loading: false,
118
+ error: error.message
119
+ }));
120
+ if (process.env.NODE_ENV !== "production") {
121
+ console.error("[TernSecure] Auth state error:", error);
122
+ }
123
+ }
124
+ );
125
+ if (process.env.NODE_ENV !== "production") {
126
+ console.log("[TernSecure] Auth listener established");
94
127
  }
95
- });
96
- return () => unsubscribe();
128
+ return () => {
129
+ unsubscribe();
130
+ if (process.env.NODE_ENV !== "production") {
131
+ console.log("[TernSecure] Auth listener cleaned up");
132
+ }
133
+ };
134
+ } catch (error) {
135
+ setAuthState((prev) => ({
136
+ ...prev,
137
+ loading: false,
138
+ error: error instanceof Error ? error.message : "Unknown error occurred"
139
+ }));
140
+ if (process.env.NODE_ENV !== "production") {
141
+ console.error("[TernSecure] Setup error:", error);
142
+ }
143
+ }
97
144
  }, []);
98
- return /* @__PURE__ */ jsxRuntime.jsx(TernSecureCtxProvider, { options: authState, children });
145
+ return /* @__PURE__ */ jsxRuntime.jsx(TernSecureCtxProvider, { children });
99
146
  }
100
147
 
101
148
  exports.TernSecureClientProvider = TernSecureClientProvider;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/utils/config.ts","../../../../src/utils/client-init.ts","../../../../src/boundary/TernSecureCtx.tsx","../../../../src/app-router/client/TernSecureProvider.tsx"],"names":["config","initializeApp","getAuth","setPersistence","browserSessionPersistence","getFirestore","getStorage","React","jsx","auth","useState","onAuthStateChanged"],"mappings":";;;;;;;;;;;;;;AAMO,IAAM,iBAAiB,OAAyB;AAAA,EACrD,MAAA,EAAQ,OAAQ,CAAA,GAAA,CAAI,4BAAgC,IAAA,EAAA;AAAA,EACpD,UAAA,EAAY,OAAQ,CAAA,GAAA,CAAI,gCAAoC,IAAA,EAAA;AAAA,EAC5D,SAAA,EAAW,OAAQ,CAAA,GAAA,CAAI,+BAAmC,IAAA,EAAA;AAAA,EAC1D,aAAA,EAAe,OAAQ,CAAA,GAAA,CAAI,mCAAuC,IAAA,EAAA;AAAA,EAClE,iBAAA,EAAmB,OAAQ,CAAA,GAAA,CAAI,wCAA4C,IAAA,EAAA;AAAA,EAC3E,KAAA,EAAO,OAAQ,CAAA,GAAA,CAAI,2BAA+B,IAAA,EAAA;AAAA,EAClD,aAAA,EAAe,OAAQ,CAAA,GAAA,CAAI,mCAAuC,IAAA,KAAA;AACpE,CAAA,CAAA;AAQO,IAAM,cAAA,GAAiB,CAACA,OAAqD,KAAA;AAClF,EAAA,MAAM,cAA6C,GAAA;AAAA,IACjD,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,eAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,SAAmB,EAAC;AAE1B,EAAA,cAAA,CAAe,QAAQ,CAAS,KAAA,KAAA;AAC9B,IAAI,IAAA,CAACA,OAAO,CAAA,KAAK,CAAG,EAAA;AAClB,MAAA,MAAA,CAAO,KAAK,CAAgD,6CAAA,EAAA,MAAA,CAAO,KAAK,CAAE,CAAA,WAAA,EAAa,CAAE,CAAA,CAAA;AAAA;AAC3F,GACD,CAAA;AAED,EAAO,OAAA;AAAA,IACL,OAAA,EAAS,OAAO,MAAW,KAAA,CA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AAA;AAAA,GACR,CAAA;AACH,EAAAH,sBAAAA,CAAM,UAAU,MAAM;AAClB,IAAA,MAAM,WAAc,GAAAI,yBAAA,CAAmBF,KAAM,EAAA,CAAC,IAAS,KAAA;AACrD,MAAA,IAAI,IAAM,EAAA;AACR,QAAa,YAAA,CAAA;AAAA,UACX,OAAS,EAAA,KAAA;AAAA,UACT,UAAY,EAAA,IAAA;AAAA,UACZ,QAAQ,IAAK,CAAA,GAAA;AAAA,UACb,KAAO,EAAA;AAAA,SACR,CAAA;AAAA,OACI,MAAA;AACL,QAAa,YAAA,CAAA;AAAA,UACX,OAAS,EAAA,KAAA;AAAA,UACT,UAAY,EAAA,KAAA;AAAA,UACZ,MAAQ,EAAA,IAAA;AAAA,UACR,KAAO,EAAA;AAAA,SACR,CAAA;AAAA;AACH,KACD,CAAA;AAED,IAAA,OAAO,MAAM,WAAY,EAAA;AAAA,GAC3B,EAAG,EAAE,CAAA;AAGL,EAAA,uBACED,cAAAA,CAAC,qBAAsB,EAAA,EAAA,OAAA,EAAS,WAC7B,QACH,EAAA,CAAA;AAEJ","file":"TernSecureProvider.cjs","sourcesContent":["import { TernSecureConfig, ConfigValidationResult } from '../types'\r\n\r\n/**\r\n * Loads Firebase configuration from environment variables\r\n * @returns {TernSecureConfig} Firebase configuration object\r\n */\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || '',\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || '',\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || '',\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || '',\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || '',\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || undefined,\r\n})\r\n\r\n/**\r\n * Validates Firebase configuration\r\n * @param {TernSecureConfig} config - Firebase configuration object\r\n * @throws {Error} If required configuration values are missing\r\n * @returns {TernSecureConfig} Validated configuration object\r\n */\r\nexport const validateConfig = (config: TernSecureConfig): ConfigValidationResult => {\r\n const requiredFields: (keyof TernSecureConfig)[] = [\r\n 'apiKey',\r\n 'authDomain',\r\n 'projectId',\r\n 'storageBucket',\r\n 'messagingSenderId',\r\n 'appId'\r\n ]\r\n\r\n const errors: string[] = []\r\n \r\n requiredFields.forEach(field => {\r\n if (!config[field]) {\r\n errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`)\r\n }\r\n })\r\n\r\n return {\r\n isValid: errors.length === 0,\r\n errors,\r\n config\r\n }\r\n}\r\n\r\n/**\r\n * Initializes configuration with validation\r\n * @throws {Error} If configuration is invalid\r\n */\r\nexport const initializeConfig = (): TernSecureConfig => {\r\n const config = loadFireConfig()\r\n const validationResult = validateConfig(config)\r\n\r\n if (!validationResult.isValid) {\r\n throw new Error(\r\n `Firebase configuration validation failed:\\n${validationResult.errors.join('\\n')}`\r\n )\r\n }\r\n\r\n return config\r\n}","import { initializeApp } from 'firebase/app';\r\nimport { getAuth, setPersistence, browserSessionPersistence } from 'firebase/auth';\r\nimport { getFirestore } from 'firebase/firestore';\r\nimport { getStorage } from 'firebase/storage';\r\nimport { initializeConfig} from './config';\r\n\r\n// Initialize immediately\r\nconst config = initializeConfig();\r\nconst clientApp = initializeApp(config)\r\nconst auth = getAuth(clientApp);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(clientApp);\r\nconst storage = getStorage(clientApp);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;","'use client'\r\n\r\nimport React from 'react'\r\n\r\ntype TernSecureState = {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\n\r\n// Create context instance only when imported on client\r\nconst TernSecureContext = React.createContext<{value: TernSecureState} | undefined>(undefined);\r\n\r\nconst useInternalContext = (hookname?: string) => {\r\n const context = React.useContext(TernSecureContext)\r\n return context\r\n}\r\n\r\nconst TernSecureCtxProvider = (\r\n props: React.PropsWithChildren<{ options: TernSecureState }>,\r\n): React.JSX.Element => {\r\n const { children, options } = props;\r\n return <TernSecureContext.Provider value={{ value: options }}>{children}</TernSecureContext.Provider>;\r\n};\r\n\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}","'use client'\r\n\r\nimport React, { useState } from 'react'\r\nimport { TernSecureAuth } from '../../utils/client-init'\r\nimport { onAuthStateChanged } from \"firebase/auth\"\r\nimport { useInternalContext, TernSecureCtxProvider } from '../../boundary/TernSecureCtx'\r\n\r\ntype TernSecureState = {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\ninterface TernSecureClientProps {\r\n children: React.ReactNode\r\n}\r\n\r\nconst auth = TernSecureAuth()\r\n\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProps) {\r\n const [authState, setAuthState] = useState<TernSecureState>({\r\n loading: true,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\nReact.useEffect(() => {\r\n const unsubscribe = onAuthStateChanged(auth, (user) => {\r\n if (user) {\r\n setAuthState({\r\n loading: false,\r\n isSignedIn: true,\r\n userId: user.uid,\r\n error: null\r\n })\r\n } else {\r\n setAuthState({\r\n loading: false,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\n }\r\n })\r\n \r\n return () => unsubscribe()\r\n }, [])\r\n\r\n\r\n return (\r\n <TernSecureCtxProvider options={authState}>\r\n {children}\r\n </TernSecureCtxProvider>\r\n )\r\n}"]}
1
+ {"version":3,"sources":["../../../../src/utils/config.ts","../../../../src/utils/client-init.ts","../../../../src/boundary/TernSecureCtx.tsx","../../../../src/app-router/client/TernSecureProvider.tsx"],"names":["config","initializeApp","getAuth","setPersistence","browserSessionPersistence","getFirestore","getStorage","React","jsx","auth","useState","onAuthStateChanged"],"mappings":";;;;;;;;;;;;;;AAMO,IAAM,iBAAiB,OAAyB;AAAA,EACrD,MAAA,EAAQ,OAAQ,CAAA,GAAA,CAAI,4BAAgC,IAAA,EAAA;AAAA,EACpD,UAAA,EAAY,OAAQ,CAAA,GAAA,CAAI,gCAAoC,IAAA,EAAA;AAAA,EAC5D,SAAA,EAAW,OAAQ,CAAA,GAAA,CAAI,+BAAmC,IAAA,EAAA;AAAA,EAC1D,aAAA,EAAe,OAAQ,CAAA,GAAA,CAAI,mCAAuC,IAAA,EAAA;AAAA,EAClE,iBAAA,EAAmB,OAAQ,CAAA,GAAA,CAAI,wCAA4C,IAAA,EAAA;AAAA,EAC3E,KAAA,EAAO,OAAQ,CAAA,GAAA,CAAI,2BAA+B,IAAA,EAAA;AAAA,EAClD,aAAA,EAAe,OAAQ,CAAA,GAAA,CAAI,mCAAuC,IAAA,KAAA;AACpE,CAAA,CAAA;AAQO,IAAM,cAAA,GAAiB,CAACA,OAAqD,KAAA;AAClF,EAAA,MAAM,cAA6C,GAAA;AAAA,IACjD,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,eAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,SAAmB,EAAC;AAE1B,EAAA,cAAA,CAAe,QAAQ,CAAS,KAAA,KAAA;AAC9B,IAAI,IAAA,CAACA,OAAO,CAAA,KAAK,CAAG,EAAA;AAClB,MAAA,MAAA,CAAO,KAAK,CAAgD,6CAAA,EAAA,MAAA,CAAO,KAAK,CAAE,CAAA,WAAA,EAAa,CAAE,CAAA,CAAA;AAAA;AAC3F,GACD,CAAA;AAED,EAAO,OAAA;AAAA,IACL,OAAA,EAAS,OAAO,MAAW,KAAA,CAAA;AAAA,IAC3B,MAAA;AAAA,IACA,MAAAA,EAAAA;AAAA,GACF;AACF,CAAA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AACzC,YAAQ,OAAA,CAAA,KAAA,CAAM,kCAAkC,KAAK,CAAA;AAAA;AACvD;AACF,OACF;AAGA,MAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,QAAA,OAAA,CAAQ,IAAI,wCAAwC,CAAA;AAAA;AAGtD,MAAA,OAAO,MAAM;AACX,QAAY,WAAA,EAAA;AACZ,QAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,UAAA,OAAA,CAAQ,IAAI,uCAAuC,CAAA;AAAA;AACrD,OACF;AAAA,aACO,KAAO,EAAA;AACd,MAAA,YAAA,CAAa,CAAS,IAAA,MAAA;AAAA,QACpB,GAAG,IAAA;AAAA,QACH,OAAS,EAAA,KAAA;AAAA,QACT,KAAO,EAAA,KAAA,YAAiB,KAAQ,GAAA,KAAA,CAAM,OAAU,GAAA;AAAA,OAChD,CAAA,CAAA;AAEF,MAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,QAAQ,OAAA,CAAA,KAAA,CAAM,6BAA6B,KAAK,CAAA;AAAA;AAClD;AACF,GACF,EAAG,EAAE,CAAA;AAEL,EACE,uBAAAD,cAAC,CAAA,qBAAA,EAAA,EACE,QACH,EAAA,CAAA;AAEJ","file":"TernSecureProvider.cjs","sourcesContent":["import { TernSecureConfig, ConfigValidationResult } from '../types'\r\n\r\n/**\r\n * Loads Firebase configuration from environment variables\r\n * @returns {TernSecureConfig} Firebase configuration object\r\n */\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || '',\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || '',\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || '',\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || '',\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || '',\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || undefined,\r\n})\r\n\r\n/**\r\n * Validates Firebase configuration\r\n * @param {TernSecureConfig} config - Firebase configuration object\r\n * @throws {Error} If required configuration values are missing\r\n * @returns {TernSecureConfig} Validated configuration object\r\n */\r\nexport const validateConfig = (config: TernSecureConfig): ConfigValidationResult => {\r\n const requiredFields: (keyof TernSecureConfig)[] = [\r\n 'apiKey',\r\n 'authDomain',\r\n 'projectId',\r\n 'storageBucket',\r\n 'messagingSenderId',\r\n 'appId'\r\n ]\r\n\r\n const errors: string[] = []\r\n \r\n requiredFields.forEach(field => {\r\n if (!config[field]) {\r\n errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`)\r\n }\r\n })\r\n\r\n return {\r\n isValid: errors.length === 0,\r\n errors,\r\n config\r\n }\r\n}\r\n\r\n/**\r\n * Initializes configuration with validation\r\n * @throws {Error} If configuration is invalid\r\n */\r\nexport const initializeConfig = (): TernSecureConfig => {\r\n const config = loadFireConfig()\r\n const validationResult = validateConfig(config)\r\n\r\n if (!validationResult.isValid) {\r\n throw new Error(\r\n `Firebase configuration validation failed:\\n${validationResult.errors.join('\\n')}`\r\n )\r\n }\r\n\r\n return config\r\n}","import { initializeApp } from 'firebase/app';\r\nimport { getAuth, setPersistence, browserSessionPersistence } from 'firebase/auth';\r\nimport { getFirestore } from 'firebase/firestore';\r\nimport { getStorage } from 'firebase/storage';\r\nimport { initializeConfig} from './config';\r\n\r\n// Initialize immediately\r\nconst config = initializeConfig();\r\nconst clientApp = initializeApp(config)\r\nconst auth = getAuth(clientApp);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(clientApp);\r\nconst storage = getStorage(clientApp);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;","'use client'\r\n\r\nimport React from 'react'\r\n\r\n// Custom error for package\r\nexport class TernSecureError extends Error {\r\n constructor(message: string) {\r\n super(`[TernSecure] ${message}`)\r\n this.name = 'TernSecureError'\r\n }\r\n}\r\n\r\n// Core types\r\nexport type TernSecureCtxValue = {\r\n dynamic: boolean\r\n}\r\n\r\nexport type TernSecureProviderProps = React.PropsWithChildren<{\r\n options?: unknown // Made optional since we're not using it\r\n}>\r\n\r\n// Context with proper null handling\r\nconst TernSecureContext = React.createContext<TernSecureCtxValue | null>(null)\r\n\r\n// Set display name for better debugging\r\nTernSecureContext.displayName = 'TernSecureContext'\r\n\r\n/**\r\n * Internal hook for context consumption\r\n * @throws {TernSecureError} When used outside client components or provider\r\n */\r\nconst useInternalContext = (hookname: string = 'useInternalContext') => {\r\n // Early check for client-side\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(`${hookname} must be used in client components`)\r\n }\r\n\r\n const context = React.useContext(TernSecureContext)\r\n \r\n if (!context) {\r\n throw new TernSecureError(\r\n `${hookname} must be used within TernSecureClientProvider`\r\n )\r\n }\r\n\r\n return context\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure\r\n * Must be used in client components only\r\n */\r\nconst TernSecureCtxProvider: React.FC<TernSecureProviderProps> = ({ \r\n children \r\n}) => {\r\n // Check for client-side rendering\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(\r\n 'TernSecureCtxProvider must be used in client components'\r\n )\r\n }\r\n\r\n // Development checks\r\n if (process.env.NODE_ENV !== 'production') {\r\n React.useEffect(() => {\r\n console.log('[TernSecure] Provider initialized in client component')\r\n }, [])\r\n }\r\n\r\n return (\r\n <TernSecureContext.Provider value={{ dynamic: true }}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}","'use client'\r\n\r\nimport React, { useState } from 'react'\r\nimport { TernSecureAuth } from '../../utils/client-init'\r\nimport { onAuthStateChanged, User } from \"firebase/auth\"\r\nimport { TernSecureCtxProvider, TernSecureError } from '../../boundary/TernSecureCtx'\r\n\r\n// Types for the provider\r\nexport type TernSecureState = {\r\n loading: boolean\r\n isSignedIn: boolean\r\n userId: string | null\r\n error: string | null\r\n}\r\n\r\ninterface TernSecureClientProps {\r\n children: React.ReactNode\r\n}\r\n\r\nconst auth = TernSecureAuth()\r\n\r\n/**\r\n * Client Provider for TernSecure\r\n * Must be used in client components only\r\n * Manages authentication state and provides it to children\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProps) {\r\n // Verify client-side execution\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError('TernSecureClientProvider must be used in client components')\r\n }\r\n\r\n const [authState, setAuthState] = useState<TernSecureState>({\r\n loading: true,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\n\r\n React.useEffect(() => {\r\n // Development checks\r\n if (process.env.NODE_ENV !== 'production') {\r\n console.log('[TernSecure] Initializing auth state listener')\r\n }\r\n\r\n try {\r\n const unsubscribe = onAuthStateChanged(auth, \r\n (user: User | null) => {\r\n setAuthState({\r\n loading: false,\r\n isSignedIn: !!user,\r\n userId: user?.uid || null,\r\n error: null\r\n })\r\n },\r\n (error) => {\r\n setAuthState(prev => ({\r\n ...prev,\r\n loading: false,\r\n error: error.message\r\n }))\r\n \r\n if (process.env.NODE_ENV !== 'production') {\r\n console.error('[TernSecure] Auth state error:', error)\r\n }\r\n }\r\n )\r\n\r\n // Development feedback\r\n if (process.env.NODE_ENV !== 'production') {\r\n console.log('[TernSecure] Auth listener established')\r\n }\r\n\r\n return () => {\r\n unsubscribe()\r\n if (process.env.NODE_ENV !== 'production') {\r\n console.log('[TernSecure] Auth listener cleaned up')\r\n }\r\n }\r\n } catch (error) {\r\n setAuthState(prev => ({\r\n ...prev,\r\n loading: false,\r\n error: error instanceof Error ? error.message : 'Unknown error occurred'\r\n }))\r\n \r\n if (process.env.NODE_ENV !== 'production') {\r\n console.error('[TernSecure] Setup error:', error)\r\n }\r\n }\r\n }, [])\r\n\r\n return (\r\n <TernSecureCtxProvider>\r\n {children}\r\n </TernSecureCtxProvider>\r\n )\r\n}\r\n\r\n// Export types for package users\r\nexport type { TernSecureClientProps }"]}
@@ -83,14 +83,32 @@ var init_client_init = __esm({
83
83
  TernSecureAuth = () => auth;
84
84
  }
85
85
  });
86
- var TernSecureContext, TernSecureCtxProvider;
86
+ var TernSecureError, TernSecureContext, TernSecureCtxProvider;
87
87
  var init_TernSecureCtx = __esm({
88
88
  "src/boundary/TernSecureCtx.tsx"() {
89
89
  "use client";
90
- TernSecureContext = React__default.default.createContext(void 0);
91
- TernSecureCtxProvider = (props) => {
92
- const { children, options } = props;
93
- return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { value: options }, children });
90
+ TernSecureError = class extends Error {
91
+ constructor(message) {
92
+ super(`[TernSecure] ${message}`);
93
+ this.name = "TernSecureError";
94
+ }
95
+ };
96
+ TernSecureContext = React__default.default.createContext(null);
97
+ TernSecureContext.displayName = "TernSecureContext";
98
+ TernSecureCtxProvider = ({
99
+ children
100
+ }) => {
101
+ if (typeof window === "undefined") {
102
+ throw new TernSecureError(
103
+ "TernSecureCtxProvider must be used in client components"
104
+ );
105
+ }
106
+ if (process.env.NODE_ENV !== "production") {
107
+ React__default.default.useEffect(() => {
108
+ console.log("[TernSecure] Provider initialized in client component");
109
+ }, []);
110
+ }
111
+ return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { dynamic: true }, children });
94
112
  };
95
113
  }
96
114
  });
@@ -101,6 +119,9 @@ __export(TernSecureProvider_exports, {
101
119
  TernSecureClientProvider: () => TernSecureClientProvider
102
120
  });
103
121
  function TernSecureClientProvider({ children }) {
122
+ if (typeof window === "undefined") {
123
+ throw new TernSecureError("TernSecureClientProvider must be used in client components");
124
+ }
104
125
  const [authState, setAuthState] = React.useState({
105
126
  loading: true,
106
127
  isSignedIn: false,
@@ -108,26 +129,52 @@ function TernSecureClientProvider({ children }) {
108
129
  error: null
109
130
  });
110
131
  React__default.default.useEffect(() => {
111
- const unsubscribe = auth$1.onAuthStateChanged(auth2, (user) => {
112
- if (user) {
113
- setAuthState({
114
- loading: false,
115
- isSignedIn: true,
116
- userId: user.uid,
117
- error: null
118
- });
119
- } else {
120
- setAuthState({
121
- loading: false,
122
- isSignedIn: false,
123
- userId: null,
124
- error: null
125
- });
132
+ if (process.env.NODE_ENV !== "production") {
133
+ console.log("[TernSecure] Initializing auth state listener");
134
+ }
135
+ try {
136
+ const unsubscribe = auth$1.onAuthStateChanged(
137
+ auth2,
138
+ (user) => {
139
+ setAuthState({
140
+ loading: false,
141
+ isSignedIn: !!user,
142
+ userId: user?.uid || null,
143
+ error: null
144
+ });
145
+ },
146
+ (error) => {
147
+ setAuthState((prev) => ({
148
+ ...prev,
149
+ loading: false,
150
+ error: error.message
151
+ }));
152
+ if (process.env.NODE_ENV !== "production") {
153
+ console.error("[TernSecure] Auth state error:", error);
154
+ }
155
+ }
156
+ );
157
+ if (process.env.NODE_ENV !== "production") {
158
+ console.log("[TernSecure] Auth listener established");
126
159
  }
127
- });
128
- return () => unsubscribe();
160
+ return () => {
161
+ unsubscribe();
162
+ if (process.env.NODE_ENV !== "production") {
163
+ console.log("[TernSecure] Auth listener cleaned up");
164
+ }
165
+ };
166
+ } catch (error) {
167
+ setAuthState((prev) => ({
168
+ ...prev,
169
+ loading: false,
170
+ error: error instanceof Error ? error.message : "Unknown error occurred"
171
+ }));
172
+ if (process.env.NODE_ENV !== "production") {
173
+ console.error("[TernSecure] Setup error:", error);
174
+ }
175
+ }
129
176
  }, []);
130
- return /* @__PURE__ */ jsxRuntime.jsx(TernSecureCtxProvider, { options: authState, children });
177
+ return /* @__PURE__ */ jsxRuntime.jsx(TernSecureCtxProvider, { children });
131
178
  }
132
179
  var auth2;
133
180
  var init_TernSecureProvider = __esm({
@@ -138,14 +185,29 @@ var init_TernSecureProvider = __esm({
138
185
  auth2 = TernSecureAuth();
139
186
  }
140
187
  });
188
+ function TernSecureLoadingFallback() {
189
+ return /* @__PURE__ */ jsxRuntime.jsx(
190
+ "div",
191
+ {
192
+ "aria-label": "Loading authentication",
193
+ role: "status",
194
+ className: "tern-secure-loading",
195
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading authentication..." })
196
+ }
197
+ );
198
+ }
141
199
  var TernSecureClientProvider2 = dynamic__default.default(
142
200
  () => Promise.resolve().then(() => (init_TernSecureProvider(), TernSecureProvider_exports)).then((mod) => mod.TernSecureClientProvider),
143
- { ssr: true }
201
+ {
202
+ loading: TernSecureLoadingFallback
203
+ }
144
204
  );
145
- function TernSecureProvider({ children }) {
146
- return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }), children: /* @__PURE__ */ jsxRuntime.jsx(TernSecureClientProvider2, { children }) });
205
+ function TernSecureServerProvider({
206
+ children
207
+ }) {
208
+ return /* @__PURE__ */ jsxRuntime.jsx(React__default.default.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(TernSecureLoadingFallback, {}), children: /* @__PURE__ */ jsxRuntime.jsx(TernSecureClientProvider2, { children }) });
147
209
  }
148
210
 
149
- exports.TernSecureProvider = TernSecureProvider;
211
+ exports.TernSecureServerProvider = TernSecureServerProvider;
150
212
  //# sourceMappingURL=TernSecureServerProvider.cjs.map
151
213
  //# sourceMappingURL=TernSecureServerProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/utils/config.ts","../../../../src/utils/client-init.ts","../../../../src/boundary/TernSecureCtx.tsx","../../../../src/app-router/client/TernSecureProvider.tsx","../../../../src/app-router/server/TernSecureServerProvider.tsx"],"names":["config","initializeApp","getAuth","setPersistence","browserSessionPersistence","getFirestore","getStorage","React","jsx","useState","onAuthStateChanged","auth","TernSecureClientProvider","dynamic","Suspense"],"mappings":";;;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A,EAAA;AAaA,IAAMA,QAAO,cAAe,EAAA;AAAA;AAAA,CAAA,CAAA;ACf5B,IAAMC,yBAA2B,GAAAC,wBAAA;AAAA,EAC/B,MAAM,OAAA,CAAA,OAAA,EAAA,CAAA,IAAA,CAAA,OAAA,uBAAA,EAAA,EAAA,0BAAA,CAAA,CAAA,CAAuC,IAAK,CAAA,CAAA,GAAA,KAAO,IAAI,wBAAwB,CAAA;AAAA,EACrF,EAAE,KAAK,IAAK;AACd,CAAA;AAMO,SAAS,kBAAA,CAAmB,EAAE,QAAA,EAAqC,EAAA;AACxE,EAAA,uBACEL,cAAAA,CAACM,cAAS,EAAA,EAAA,QAAA,kBAAUN,cAAC,CAAA,KAAA,EAAA,EAAI,QAAU,EAAA,YAAA,EAAA,CAAA,EACjC,QAAAA,kBAAAA,cAAAA,CAACI,yBAAA,EAAA,EACE,UACH,CACF,EAAA,CAAA;AAEJ","file":"TernSecureServerProvider.cjs","sourcesContent":["import { TernSecureConfig, ConfigValidationResult } from '../types'\r\n\r\n/**\r\n * Loads Firebase configuration from environment variables\r\n * @returns {TernSecureConfig} Firebase configuration object\r\n */\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || '',\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || '',\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || '',\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || '',\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || '',\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || undefined,\r\n})\r\n\r\n/**\r\n * Validates Firebase configuration\r\n * @param {TernSecureConfig} config - Firebase configuration object\r\n * @throws {Error} If required configuration values are missing\r\n * @returns {TernSecureConfig} Validated configuration object\r\n */\r\nexport const validateConfig = (config: TernSecureConfig): ConfigValidationResult => {\r\n const requiredFields: (keyof TernSecureConfig)[] = [\r\n 'apiKey',\r\n 'authDomain',\r\n 'projectId',\r\n 'storageBucket',\r\n 'messagingSenderId',\r\n 'appId'\r\n ]\r\n\r\n const errors: string[] = []\r\n \r\n requiredFields.forEach(field => {\r\n if (!config[field]) {\r\n errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`)\r\n }\r\n })\r\n\r\n return {\r\n isValid: errors.length === 0,\r\n errors,\r\n config\r\n }\r\n}\r\n\r\n/**\r\n * Initializes configuration with validation\r\n * @throws {Error} If configuration is invalid\r\n */\r\nexport const initializeConfig = (): TernSecureConfig => {\r\n const config = loadFireConfig()\r\n const validationResult = validateConfig(config)\r\n\r\n if (!validationResult.isValid) {\r\n throw new Error(\r\n `Firebase configuration validation failed:\\n${validationResult.errors.join('\\n')}`\r\n )\r\n }\r\n\r\n return config\r\n}","import { initializeApp } from 'firebase/app';\r\nimport { getAuth, setPersistence, browserSessionPersistence } from 'firebase/auth';\r\nimport { getFirestore } from 'firebase/firestore';\r\nimport { getStorage } from 'firebase/storage';\r\nimport { initializeConfig} from './config';\r\n\r\n// Initialize immediately\r\nconst config = initializeConfig();\r\nconst clientApp = initializeApp(config)\r\nconst auth = getAuth(clientApp);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(clientApp);\r\nconst storage = getStorage(clientApp);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;","'use client'\r\n\r\nimport React from 'react'\r\n\r\ntype TernSecureState = {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\n\r\n// Create context instance only when imported on client\r\nconst TernSecureContext = React.createContext<{value: TernSecureState} | undefined>(undefined);\r\n\r\nconst useInternalContext = (hookname?: string) => {\r\n const context = React.useContext(TernSecureContext)\r\n return context\r\n}\r\n\r\nconst TernSecureCtxProvider = (\r\n props: React.PropsWithChildren<{ options: TernSecureState }>,\r\n): React.JSX.Element => {\r\n const { children, options } = props;\r\n return <TernSecureContext.Provider value={{ value: options }}>{children}</TernSecureContext.Provider>;\r\n};\r\n\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}","'use client'\r\n\r\nimport React, { useState } from 'react'\r\nimport { TernSecureAuth } from '../../utils/client-init'\r\nimport { onAuthStateChanged } from \"firebase/auth\"\r\nimport { useInternalContext, TernSecureCtxProvider } from '../../boundary/TernSecureCtx'\r\n\r\ntype TernSecureState = {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\ninterface TernSecureClientProps {\r\n children: React.ReactNode\r\n}\r\n\r\nconst auth = TernSecureAuth()\r\n\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProps) {\r\n const [authState, setAuthState] = useState<TernSecureState>({\r\n loading: true,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\nReact.useEffect(() => {\r\n const unsubscribe = onAuthStateChanged(auth, (user) => {\r\n if (user) {\r\n setAuthState({\r\n loading: false,\r\n isSignedIn: true,\r\n userId: user.uid,\r\n error: null\r\n })\r\n } else {\r\n setAuthState({\r\n loading: false,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\n }\r\n })\r\n \r\n return () => unsubscribe()\r\n }, [])\r\n\r\n\r\n return (\r\n <TernSecureCtxProvider options={authState}>\r\n {children}\r\n </TernSecureCtxProvider>\r\n )\r\n}","import dynamic from 'next/dynamic'\r\nimport React, { ReactNode, Suspense } from \"react\"\r\n\r\nconst TernSecureClientProvider = dynamic(\r\n () => import(\"../client/TernSecureProvider\").then(mod => mod.TernSecureClientProvider),\r\n { ssr: true }\r\n)\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode\r\n}\r\n\r\nexport function TernSecureProvider({ children }: TernSecureProviderProps) {\r\n return (\r\n <Suspense fallback={<div>Loading...</div>}>\r\n <TernSecureClientProvider>\r\n {children}\r\n </TernSecureClientProvider>\r\n </Suspense>\r\n )\r\n}"]}
1
+ {"version":3,"sources":["../../../../src/utils/config.ts","../../../../src/utils/client-init.ts","../../../../src/boundary/TernSecureCtx.tsx","../../../../src/app-router/client/TernSecureProvider.tsx","../../../../src/app-router/server/TernSecureServerProvider.tsx"],"names":["config","initializeApp","getAuth","setPersistence","browserSessionPersistence","getFirestore","getStorage","React","jsx","useState","onAuthStateChanged","auth","TernSecureClientProvider","dynamic"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAMa,gBAgBA,cA6BA,EAAA,gBAAA;AAnDb,IAAA,WAAA,GAAA,KAAA,CAAA;AAAA,EAAA,qBAAA,GAAA;AAMO,IAAM,iBAAiB,OAAyB;AAAA,MACrD,MAAA,EAAQ,OAAQ,CAAA,GAAA,CAAI,4BAAgC,IAAA,EAAA;AAAA,MACpD,UAAA,EAAY,OAAQ,CAAA,GAAA,CAAI,gCAAoC,IAAA,EAAA;AAAA,MAC5D,SAAA,EAAW,OAAQ,CAAA,GAAA,CAAI,+BAAmC,IAAA,EAAA;AAAA,MAC1D,aAAA,EAAe,OAAQ,CAAA,GAAA,CAAI,mCAAuC,IAAA,EAAA;AAAA,MAClE,iBAAA,EAAmB,OAAQ,CAAA,GAAA,CAAI,wCAA4C,IAAA,EAAA;AAAA,MAC3E,KAAA,EAAO,OAAQ,CAAA,GAAA,CAAI,2BAA+B,IAAA,EAAA;AAAA,MAClD,aAAA,EAAe,OAAQ,CAAA,GAAA,CAAI,mCAAuC,IAAA,KAAA;AAAA,KACpE,CAAA;AAQO,IAAM,cAAA,GAAiB,CAACA,OAAqD,KAAA;AAClF,MAAA,MAAM,cAA6C,GAAA;AAAA,QACjD,QAAA;AAAA,QACA,YAAA;AAAA,QACA,WAAA;AAAA,QACA,eAAA;AAAA,QACA,mBAAA;AAAA,QACA;AA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AAMO,SAAS,wBAAyB,CAAA;AAAA,EACvC;AACF,CAEG,EAAA;AACD,EAAA,uBACEL,cAAAA,CAACD,sBAAM,CAAA,QAAA,EAAN,EAAe,QAAU,kBAAAC,cAAC,CAAA,yBAAA,EAAA,EAA0B,GACnD,QAAAA,kBAAAA,cAAAA,CAACI,yBAAA,EAAA,EACE,UACH,CACF,EAAA,CAAA;AAEJ","file":"TernSecureServerProvider.cjs","sourcesContent":["import { TernSecureConfig, ConfigValidationResult } from '../types'\r\n\r\n/**\r\n * Loads Firebase configuration from environment variables\r\n * @returns {TernSecureConfig} Firebase configuration object\r\n */\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || '',\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || '',\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || '',\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || '',\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || '',\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || undefined,\r\n})\r\n\r\n/**\r\n * Validates Firebase configuration\r\n * @param {TernSecureConfig} config - Firebase configuration object\r\n * @throws {Error} If required configuration values are missing\r\n * @returns {TernSecureConfig} Validated configuration object\r\n */\r\nexport const validateConfig = (config: TernSecureConfig): ConfigValidationResult => {\r\n const requiredFields: (keyof TernSecureConfig)[] = [\r\n 'apiKey',\r\n 'authDomain',\r\n 'projectId',\r\n 'storageBucket',\r\n 'messagingSenderId',\r\n 'appId'\r\n ]\r\n\r\n const errors: string[] = []\r\n \r\n requiredFields.forEach(field => {\r\n if (!config[field]) {\r\n errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`)\r\n }\r\n })\r\n\r\n return {\r\n isValid: errors.length === 0,\r\n errors,\r\n config\r\n }\r\n}\r\n\r\n/**\r\n * Initializes configuration with validation\r\n * @throws {Error} If configuration is invalid\r\n */\r\nexport const initializeConfig = (): TernSecureConfig => {\r\n const config = loadFireConfig()\r\n const validationResult = validateConfig(config)\r\n\r\n if (!validationResult.isValid) {\r\n throw new Error(\r\n `Firebase configuration validation failed:\\n${validationResult.errors.join('\\n')}`\r\n )\r\n }\r\n\r\n return config\r\n}","import { initializeApp } from 'firebase/app';\r\nimport { getAuth, setPersistence, browserSessionPersistence } from 'firebase/auth';\r\nimport { getFirestore } from 'firebase/firestore';\r\nimport { getStorage } from 'firebase/storage';\r\nimport { initializeConfig} from './config';\r\n\r\n// Initialize immediately\r\nconst config = initializeConfig();\r\nconst clientApp = initializeApp(config)\r\nconst auth = getAuth(clientApp);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(clientApp);\r\nconst storage = getStorage(clientApp);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;","'use client'\r\n\r\nimport React from 'react'\r\n\r\n// Custom error for package\r\nexport class TernSecureError extends Error {\r\n constructor(message: string) {\r\n super(`[TernSecure] ${message}`)\r\n this.name = 'TernSecureError'\r\n }\r\n}\r\n\r\n// Core types\r\nexport type TernSecureCtxValue = {\r\n dynamic: boolean\r\n}\r\n\r\nexport type TernSecureProviderProps = React.PropsWithChildren<{\r\n options?: unknown // Made optional since we're not using it\r\n}>\r\n\r\n// Context with proper null handling\r\nconst TernSecureContext = React.createContext<TernSecureCtxValue | null>(null)\r\n\r\n// Set display name for better debugging\r\nTernSecureContext.displayName = 'TernSecureContext'\r\n\r\n/**\r\n * Internal hook for context consumption\r\n * @throws {TernSecureError} When used outside client components or provider\r\n */\r\nconst useInternalContext = (hookname: string = 'useInternalContext') => {\r\n // Early check for client-side\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(`${hookname} must be used in client components`)\r\n }\r\n\r\n const context = React.useContext(TernSecureContext)\r\n \r\n if (!context) {\r\n throw new TernSecureError(\r\n `${hookname} must be used within TernSecureClientProvider`\r\n )\r\n }\r\n\r\n return context\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure\r\n * Must be used in client components only\r\n */\r\nconst TernSecureCtxProvider: React.FC<TernSecureProviderProps> = ({ \r\n children \r\n}) => {\r\n // Check for client-side rendering\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(\r\n 'TernSecureCtxProvider must be used in client components'\r\n )\r\n }\r\n\r\n // Development checks\r\n if (process.env.NODE_ENV !== 'production') {\r\n React.useEffect(() => {\r\n console.log('[TernSecure] Provider initialized in client component')\r\n }, [])\r\n }\r\n\r\n return (\r\n <TernSecureContext.Provider value={{ dynamic: true }}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}","'use client'\r\n\r\nimport React, { useState } from 'react'\r\nimport { TernSecureAuth } from '../../utils/client-init'\r\nimport { onAuthStateChanged, User } from \"firebase/auth\"\r\nimport { TernSecureCtxProvider, TernSecureError } from '../../boundary/TernSecureCtx'\r\n\r\n// Types for the provider\r\nexport type TernSecureState = {\r\n loading: boolean\r\n isSignedIn: boolean\r\n userId: string | null\r\n error: string | null\r\n}\r\n\r\ninterface TernSecureClientProps {\r\n children: React.ReactNode\r\n}\r\n\r\nconst auth = TernSecureAuth()\r\n\r\n/**\r\n * Client Provider for TernSecure\r\n * Must be used in client components only\r\n * Manages authentication state and provides it to children\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProps) {\r\n // Verify client-side execution\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError('TernSecureClientProvider must be used in client components')\r\n }\r\n\r\n const [authState, setAuthState] = useState<TernSecureState>({\r\n loading: true,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\n\r\n React.useEffect(() => {\r\n // Development checks\r\n if (process.env.NODE_ENV !== 'production') {\r\n console.log('[TernSecure] Initializing auth state listener')\r\n }\r\n\r\n try {\r\n const unsubscribe = onAuthStateChanged(auth, \r\n (user: User | null) => {\r\n setAuthState({\r\n loading: false,\r\n isSignedIn: !!user,\r\n userId: user?.uid || null,\r\n error: null\r\n })\r\n },\r\n (error) => {\r\n setAuthState(prev => ({\r\n ...prev,\r\n loading: false,\r\n error: error.message\r\n }))\r\n \r\n if (process.env.NODE_ENV !== 'production') {\r\n console.error('[TernSecure] Auth state error:', error)\r\n }\r\n }\r\n )\r\n\r\n // Development feedback\r\n if (process.env.NODE_ENV !== 'production') {\r\n console.log('[TernSecure] Auth listener established')\r\n }\r\n\r\n return () => {\r\n unsubscribe()\r\n if (process.env.NODE_ENV !== 'production') {\r\n console.log('[TernSecure] Auth listener cleaned up')\r\n }\r\n }\r\n } catch (error) {\r\n setAuthState(prev => ({\r\n ...prev,\r\n loading: false,\r\n error: error instanceof Error ? error.message : 'Unknown error occurred'\r\n }))\r\n \r\n if (process.env.NODE_ENV !== 'production') {\r\n console.error('[TernSecure] Setup error:', error)\r\n }\r\n }\r\n }, [])\r\n\r\n return (\r\n <TernSecureCtxProvider>\r\n {children}\r\n </TernSecureCtxProvider>\r\n )\r\n}\r\n\r\n// Export types for package users\r\nexport type { TernSecureClientProps }","import React from \"react\"\r\nimport dynamic from 'next/dynamic'\r\nimport type { TernSecureClientProps } from '../client/TernSecureProvider'\r\n\r\n// Loading fallback component\r\nfunction TernSecureLoadingFallback() {\r\n return (\r\n <div \r\n aria-label=\"Loading authentication\" \r\n role=\"status\"\r\n className=\"tern-secure-loading\"\r\n >\r\n <span className=\"sr-only\">Loading authentication...</span>\r\n </div>\r\n )\r\n}\r\n\r\n// Dynamically import the client provider\r\nconst TernSecureClientProvider = dynamic<TernSecureClientProps>(\r\n () => import('../client/TernSecureProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n loading: TernSecureLoadingFallback\r\n }\r\n)\r\n\r\n/**\r\n * Root Provider for TernSecure\r\n * Use this in your Next.js App Router root layout\r\n */\r\nexport function TernSecureServerProvider({ \r\n children \r\n}: { \r\n children: React.ReactNode \r\n}) {\r\n return (\r\n <React.Suspense fallback={<TernSecureLoadingFallback />}>\r\n <TernSecureClientProvider>\r\n {children}\r\n </TernSecureClientProvider>\r\n </React.Suspense>\r\n )\r\n}"]}
@@ -7,17 +7,44 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
8
8
  var React__default = /*#__PURE__*/_interopDefault(React);
9
9
 
10
- var TernSecureContext = React__default.default.createContext(void 0);
11
- var useInternalContext = (hookname) => {
10
+ var TernSecureError = class extends Error {
11
+ constructor(message) {
12
+ super(`[TernSecure] ${message}`);
13
+ this.name = "TernSecureError";
14
+ }
15
+ };
16
+ var TernSecureContext = React__default.default.createContext(null);
17
+ TernSecureContext.displayName = "TernSecureContext";
18
+ var useInternalContext = (hookname = "useInternalContext") => {
19
+ if (typeof window === "undefined") {
20
+ throw new TernSecureError(`${hookname} must be used in client components`);
21
+ }
12
22
  const context = React__default.default.useContext(TernSecureContext);
23
+ if (!context) {
24
+ throw new TernSecureError(
25
+ `${hookname} must be used within TernSecureClientProvider`
26
+ );
27
+ }
13
28
  return context;
14
29
  };
15
- var TernSecureCtxProvider = (props) => {
16
- const { children, options } = props;
17
- return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { value: options }, children });
30
+ var TernSecureCtxProvider = ({
31
+ children
32
+ }) => {
33
+ if (typeof window === "undefined") {
34
+ throw new TernSecureError(
35
+ "TernSecureCtxProvider must be used in client components"
36
+ );
37
+ }
38
+ if (process.env.NODE_ENV !== "production") {
39
+ React__default.default.useEffect(() => {
40
+ console.log("[TernSecure] Provider initialized in client component");
41
+ }, []);
42
+ }
43
+ return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { dynamic: true }, children });
18
44
  };
19
45
 
20
46
  exports.TernSecureCtxProvider = TernSecureCtxProvider;
47
+ exports.TernSecureError = TernSecureError;
21
48
  exports.useInternalContext = useInternalContext;
22
49
  //# sourceMappingURL=TernSecureCtx.cjs.map
23
50
  //# sourceMappingURL=TernSecureCtx.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/boundary/TernSecureCtx.tsx"],"names":["React","jsx"],"mappings":";;;;;;;;;AAaA,IAAM,iBAAA,GAAoBA,sBAAM,CAAA,aAAA,CAAoD,KAAS,CAAA,CAAA;AAEvF,IAAA,kBAAA,GAAqB,CAAC,QAAsB,KAAA;AAChD,EAAM,MAAA,OAAA,GAAUA,sBAAM,CAAA,UAAA,CAAW,iBAAiB,CAAA;AAClD,EAAO,OAAA,OAAA;AACT;AAEM,IAAA,qBAAA,GAAwB,CAC5B,KACsB,KAAA;AACtB,EAAM,MAAA,EAAE,QAAU,EAAA,OAAA,EAAY,GAAA,KAAA;AAC9B,EAAO,uBAAAC,cAAA,CAAC,kBAAkB,QAAlB,EAAA,EAA2B,OAAO,EAAE,KAAA,EAAO,OAAQ,EAAA,EAAI,QAAS,EAAA,CAAA;AAC1E","file":"TernSecureCtx.cjs","sourcesContent":["'use client'\r\n\r\nimport React from 'react'\r\n\r\ntype TernSecureState = {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\n\r\n// Create context instance only when imported on client\r\nconst TernSecureContext = React.createContext<{value: TernSecureState} | undefined>(undefined);\r\n\r\nconst useInternalContext = (hookname?: string) => {\r\n const context = React.useContext(TernSecureContext)\r\n return context\r\n}\r\n\r\nconst TernSecureCtxProvider = (\r\n props: React.PropsWithChildren<{ options: TernSecureState }>,\r\n): React.JSX.Element => {\r\n const { children, options } = props;\r\n return <TernSecureContext.Provider value={{ value: options }}>{children}</TernSecureContext.Provider>;\r\n};\r\n\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}"]}
1
+ {"version":3,"sources":["../../../src/boundary/TernSecureCtx.tsx"],"names":["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.cjs","sourcesContent":["'use client'\r\n\r\nimport React from 'react'\r\n\r\n// Custom error for package\r\nexport class TernSecureError extends Error {\r\n constructor(message: string) {\r\n super(`[TernSecure] ${message}`)\r\n this.name = 'TernSecureError'\r\n }\r\n}\r\n\r\n// Core types\r\nexport type TernSecureCtxValue = {\r\n dynamic: boolean\r\n}\r\n\r\nexport type TernSecureProviderProps = React.PropsWithChildren<{\r\n options?: unknown // Made optional since we're not using it\r\n}>\r\n\r\n// Context with proper null handling\r\nconst TernSecureContext = React.createContext<TernSecureCtxValue | null>(null)\r\n\r\n// Set display name for better debugging\r\nTernSecureContext.displayName = 'TernSecureContext'\r\n\r\n/**\r\n * Internal hook for context consumption\r\n * @throws {TernSecureError} When used outside client components or provider\r\n */\r\nconst useInternalContext = (hookname: string = 'useInternalContext') => {\r\n // Early check for client-side\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(`${hookname} must be used in client components`)\r\n }\r\n\r\n const context = React.useContext(TernSecureContext)\r\n \r\n if (!context) {\r\n throw new TernSecureError(\r\n `${hookname} must be used within TernSecureClientProvider`\r\n )\r\n }\r\n\r\n return context\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure\r\n * Must be used in client components only\r\n */\r\nconst TernSecureCtxProvider: React.FC<TernSecureProviderProps> = ({ \r\n children \r\n}) => {\r\n // Check for client-side rendering\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(\r\n 'TernSecureCtxProvider must be used in client components'\r\n )\r\n }\r\n\r\n // Development checks\r\n if (process.env.NODE_ENV !== 'production') {\r\n React.useEffect(() => {\r\n console.log('[TernSecure] Provider initialized in client component')\r\n }, [])\r\n }\r\n\r\n return (\r\n <TernSecureContext.Provider value={{ dynamic: true }}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}"]}
@@ -7,25 +7,40 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
8
8
  var React__default = /*#__PURE__*/_interopDefault(React);
9
9
 
10
- var TernSecureContext = React__default.default.createContext(void 0);
11
- var useInternalContext = (hookname) => {
10
+ var TernSecureError = class extends Error {
11
+ constructor(message) {
12
+ super(`[TernSecure] ${message}`);
13
+ this.name = "TernSecureError";
14
+ }
15
+ };
16
+ var TernSecureContext = React__default.default.createContext(null);
17
+ TernSecureContext.displayName = "TernSecureContext";
18
+ var useInternalContext = (hookname = "useInternalContext") => {
19
+ if (typeof window === "undefined") {
20
+ throw new TernSecureError(`${hookname} must be used in client components`);
21
+ }
12
22
  const context = React__default.default.useContext(TernSecureContext);
23
+ if (!context) {
24
+ throw new TernSecureError(
25
+ `${hookname} must be used within TernSecureClientProvider`
26
+ );
27
+ }
13
28
  return context;
14
29
  };
15
30
 
16
31
  // src/boundary/hooks/use-auth.ts
17
32
  function useAuth() {
18
- const context = useInternalContext();
19
- if (!context || !context.value) {
20
- throw new Error("useAuth must be used within a TernSecureClientProvider");
33
+ const context = useInternalContext("useAuth");
34
+ if (!context.dynamic) {
35
+ throw new TernSecureError("Authentication context not properly initialized");
21
36
  }
22
- const { userId, loading, error, isSignedIn } = context.value;
23
- return {
24
- userId,
25
- loading,
26
- error,
27
- isSignedIn
37
+ const defaultState = {
38
+ loading: true,
39
+ isSignedIn: false,
40
+ userId: null,
41
+ error: null
28
42
  };
43
+ return defaultState;
29
44
  }
30
45
 
31
46
  exports.useAuth = useAuth;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/boundary/TernSecureCtx.tsx","../../../../src/boundary/hooks/use-auth.ts"],"names":["React"],"mappings":";;;;;;;;;AAaA,IAAM,iBAAA,GAAoBA,sBAAM,CAAA,aAAA,CAAoD,KAAS,CAAA,CAAA;AAE7F,IAAM,kBAAA,GAAqB,CAAC,QAAsB,KAAA;AAChD,EAAM,MAAA,OAAA,GAAUA,sBAAM,CAAA,UAAA,CAAW,iBAAiB,CAAA;AAClD,EAAO,OAAA,OAAA;AACT,CAAA;;;ACPO,SAAS,OAAqB,GAAA;AACnC,EAAM,MAAA,OAAA,GAAU,mBAA4B,CAAA;AAE5C,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,OAAA,CAAQ,KAAO,EAAA;AAC9B,IAAM,MAAA,IAAI,MAAM,wDAAwD,CAAA;AAAA;AAG1E,EAAA,MAAM,EAAE,MAAQ,EAAA,OAAA,EAAS,KAAO,EAAA,UAAA,KAAe,OAAQ,CAAA,KAAA;AAEvD,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"use-auth.cjs","sourcesContent":["'use client'\r\n\r\nimport React from 'react'\r\n\r\ntype TernSecureState = {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\n\r\n// Create context instance only when imported on client\r\nconst TernSecureContext = React.createContext<{value: TernSecureState} | undefined>(undefined);\r\n\r\nconst useInternalContext = (hookname?: string) => {\r\n const context = React.useContext(TernSecureContext)\r\n return context\r\n}\r\n\r\nconst TernSecureCtxProvider = (\r\n props: React.PropsWithChildren<{ options: TernSecureState }>,\r\n): React.JSX.Element => {\r\n const { children, options } = props;\r\n return <TernSecureContext.Provider value={{ value: options }}>{children}</TernSecureContext.Provider>;\r\n};\r\n\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}","'use client'\r\n\r\nimport { useInternalContext } from '../TernSecureCtx'\r\n\r\nexport interface AuthState {\r\n userId: string | null\r\n loading: boolean\r\n error: string | null\r\n isSignedIn: boolean\r\n}\r\n\r\nexport function useAuth(): AuthState {\r\n const context = useInternalContext('useAuth')\r\n \r\n if (!context || !context.value) {\r\n throw new Error('useAuth must be used within a TernSecureClientProvider')\r\n }\r\n\r\n const { userId, loading, error, isSignedIn } = context.value\r\n\r\n return {\r\n userId,\r\n loading,\r\n error,\r\n isSignedIn\r\n }\r\n}"]}
1
+ {"version":3,"sources":["../../../../src/boundary/TernSecureCtx.tsx","../../../../src/boundary/hooks/use-auth.ts"],"names":["React"],"mappings":";;;;;;;;;AAKO,IAAM,eAAA,GAAN,cAA8B,KAAM,CAAA;AAAA,EACzC,YAAY,OAAiB,EAAA;AAC3B,IAAM,KAAA,CAAA,CAAA,aAAA,EAAgB,OAAO,CAAE,CAAA,CAAA;AAC/B,IAAA,IAAA,CAAK,IAAO,GAAA,iBAAA;AAAA;AAEhB,CAAA;AAYA,IAAM,iBAAA,GAAoBA,sBAAM,CAAA,aAAA,CAAyC,IAAI,CAAA;AAG7E,iBAAA,CAAkB,WAAc,GAAA,mBAAA;AAMhC,IAAM,kBAAA,GAAqB,CAAC,QAAA,GAAmB,oBAAyB,KAAA;AAEtE,EAAI,IAAA,OAAO,WAAW,WAAa,EAAA;AACjC,IAAA,MAAM,IAAI,eAAA,CAAgB,CAAG,EAAA,QAAQ,CAAoC,kCAAA,CAAA,CAAA;AAAA;AAG3E,EAAM,MAAA,OAAA,GAAUA,sBAAM,CAAA,UAAA,CAAW,iBAAiB,CAAA;AAElD,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAA,MAAM,IAAI,eAAA;AAAA,MACR,GAAG,QAAQ,CAAA,6CAAA;AAAA,KACb;AAAA;AAGF,EAAO,OAAA,OAAA;AACT,CAAA;;;ACxBO,SAAS,OAA2B,GAAA;AAEzC,EAAM,MAAA,OAAA,GAAU,mBAAmB,SAAS,CAAA;AAG5C,EAAI,IAAA,CAAC,QAAQ,OAAS,EAAA;AACpB,IAAM,MAAA,IAAI,gBAAgB,iDAAiD,CAAA;AAAA;AAI7E,EAAA,MAAM,YAAgC,GAAA;AAAA,IACpC,OAAS,EAAA,IAAA;AAAA,IACT,UAAY,EAAA,KAAA;AAAA,IACZ,MAAQ,EAAA,IAAA;AAAA,IACR,KAAO,EAAA;AAAA,GACT;AAEA,EAAO,OAAA,YAAA;AACT","file":"use-auth.cjs","sourcesContent":["'use client'\r\n\r\nimport React from 'react'\r\n\r\n// Custom error for package\r\nexport class TernSecureError extends Error {\r\n constructor(message: string) {\r\n super(`[TernSecure] ${message}`)\r\n this.name = 'TernSecureError'\r\n }\r\n}\r\n\r\n// Core types\r\nexport type TernSecureCtxValue = {\r\n dynamic: boolean\r\n}\r\n\r\nexport type TernSecureProviderProps = React.PropsWithChildren<{\r\n options?: unknown // Made optional since we're not using it\r\n}>\r\n\r\n// Context with proper null handling\r\nconst TernSecureContext = React.createContext<TernSecureCtxValue | null>(null)\r\n\r\n// Set display name for better debugging\r\nTernSecureContext.displayName = 'TernSecureContext'\r\n\r\n/**\r\n * Internal hook for context consumption\r\n * @throws {TernSecureError} When used outside client components or provider\r\n */\r\nconst useInternalContext = (hookname: string = 'useInternalContext') => {\r\n // Early check for client-side\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(`${hookname} must be used in client components`)\r\n }\r\n\r\n const context = React.useContext(TernSecureContext)\r\n \r\n if (!context) {\r\n throw new TernSecureError(\r\n `${hookname} must be used within TernSecureClientProvider`\r\n )\r\n }\r\n\r\n return context\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure\r\n * Must be used in client components only\r\n */\r\nconst TernSecureCtxProvider: React.FC<TernSecureProviderProps> = ({ \r\n children \r\n}) => {\r\n // Check for client-side rendering\r\n if (typeof window === 'undefined') {\r\n throw new TernSecureError(\r\n 'TernSecureCtxProvider must be used in client components'\r\n )\r\n }\r\n\r\n // Development checks\r\n if (process.env.NODE_ENV !== 'production') {\r\n React.useEffect(() => {\r\n console.log('[TernSecure] Provider initialized in client component')\r\n }, [])\r\n }\r\n\r\n return (\r\n <TernSecureContext.Provider value={{ dynamic: true }}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\nexport {\r\n useInternalContext,\r\n TernSecureCtxProvider\r\n}","'use client'\r\n\r\nimport { useInternalContext, TernSecureError } from '../TernSecureCtx'\r\nimport type { TernSecureState } from '../../app-router/client/TernSecureProvider'\r\n\r\n/**\r\n * Hook to access TernSecure authentication state\r\n * Must be used within TernSecureClientProvider and in client components\r\n * \r\n * @throws {TernSecureError} When used outside client components or provider\r\n * @returns {TernSecureState} Current authentication state\r\n * \r\n * @example\r\n * function AuthenticatedComponent() {\r\n * const { isSignedIn, loading, userId, error } = useAuth()\r\n * \r\n * if (loading) return <div>Loading...</div>\r\n * if (error) return <div>Error: {error}</div>\r\n * \r\n * return isSignedIn ? <div>Welcome user: {userId}</div> : <div>Please sign in</div>\r\n * }\r\n */\r\nexport function useAuth(): TernSecureState {\r\n // useInternalContext already handles client-side and provider checks\r\n const context = useInternalContext('useAuth')\r\n\r\n // Since our context only has dynamic flag, we need to access the parent provider\r\n if (!context.dynamic) {\r\n throw new TernSecureError('Authentication context not properly initialized')\r\n }\r\n\r\n // Get auth state from the nearest TernSecureClientProvider\r\n const defaultState: TernSecureState = {\r\n loading: true,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n }\r\n\r\n return defaultState\r\n}\r\n\r\n// Re-export the state type for consumers\r\nexport type { TernSecureState }"]}