@tern-secure/nextjs 3.1.57 → 3.1.59
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/cjs/app-router/client/TernSecureProvider.cjs +23 -70
- package/dist/cjs/app-router/client/TernSecureProvider.cjs.map +1 -1
- package/dist/cjs/app-router/server/TernSecureServerProvider.cjs +77 -182
- package/dist/cjs/app-router/server/TernSecureServerProvider.cjs.map +1 -1
- package/dist/cjs/boundary/TernSecureCtx.cjs +5 -32
- package/dist/cjs/boundary/TernSecureCtx.cjs.map +1 -1
- package/dist/cjs/boundary/hooks/use-auth.cjs +64 -21
- package/dist/cjs/boundary/hooks/use-auth.cjs.map +1 -1
- package/dist/cjs/index.cjs +104 -220
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/app-router/client/TernSecureProvider.d.ts +1 -12
- package/dist/esm/app-router/client/TernSecureProvider.js +3 -67
- package/dist/esm/app-router/client/TernSecureProvider.js.map +1 -1
- package/dist/esm/app-router/server/TernSecureServerProvider.d.ts +6 -9
- package/dist/esm/app-router/server/TernSecureServerProvider.js +5 -1
- package/dist/esm/boundary/TernSecureCtx.d.ts +12 -19
- package/dist/esm/boundary/TernSecureCtx.js +1 -1
- package/dist/esm/boundary/hooks/use-auth.d.ts +13 -23
- package/dist/esm/boundary/hooks/use-auth.js +4 -2
- package/dist/esm/chunk-3D5IN6EL.js +11 -0
- package/dist/esm/chunk-3D5IN6EL.js.map +1 -0
- package/dist/esm/chunk-F7XKLY6Y.js +40 -0
- package/dist/esm/chunk-F7XKLY6Y.js.map +1 -0
- package/dist/esm/chunk-I2PGODCQ.js +17 -0
- package/dist/esm/chunk-I2PGODCQ.js.map +1 -0
- package/dist/esm/chunk-KUYDOUCP.js +24 -0
- package/dist/esm/chunk-KUYDOUCP.js.map +1 -0
- package/dist/esm/index.d.ts +5 -8
- package/dist/esm/index.js +4 -8
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-32DZLLHE.js +0 -43
- package/dist/esm/chunk-32DZLLHE.js.map +0 -1
- package/dist/esm/chunk-FMHBRXHR.js +0 -20
- package/dist/esm/chunk-FMHBRXHR.js.map +0 -1
- package/dist/esm/chunk-S2ODB3YJ.js +0 -31
- package/dist/esm/chunk-S2ODB3YJ.js.map +0 -1
|
@@ -1,46 +1,89 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
+
var app = require('firebase/app');
|
|
5
|
+
var auth$1 = require('firebase/auth');
|
|
6
|
+
var firestore = require('firebase/firestore');
|
|
7
|
+
var storage = require('firebase/storage');
|
|
4
8
|
require('react/jsx-runtime');
|
|
5
9
|
|
|
6
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
11
|
|
|
8
12
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
// src/utils/config.ts
|
|
15
|
+
var loadFireConfig = () => ({
|
|
16
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || "",
|
|
17
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || "",
|
|
18
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || "",
|
|
19
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || "",
|
|
20
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || "",
|
|
21
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "",
|
|
22
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || void 0
|
|
23
|
+
});
|
|
24
|
+
var validateConfig = (config2) => {
|
|
25
|
+
const requiredFields = [
|
|
26
|
+
"apiKey",
|
|
27
|
+
"authDomain",
|
|
28
|
+
"projectId",
|
|
29
|
+
"storageBucket",
|
|
30
|
+
"messagingSenderId",
|
|
31
|
+
"appId"
|
|
32
|
+
];
|
|
33
|
+
const errors = [];
|
|
34
|
+
requiredFields.forEach((field) => {
|
|
35
|
+
if (!config2[field]) {
|
|
36
|
+
errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
isValid: errors.length === 0,
|
|
41
|
+
errors,
|
|
42
|
+
config: config2
|
|
43
|
+
};
|
|
15
44
|
};
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
throw new
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!context) {
|
|
24
|
-
throw new TernSecureError(
|
|
25
|
-
`${hookname} must be used within TernSecureClientProvider`
|
|
45
|
+
var initializeConfig = () => {
|
|
46
|
+
const config2 = loadFireConfig();
|
|
47
|
+
const validationResult = validateConfig(config2);
|
|
48
|
+
if (!validationResult.isValid) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Firebase configuration validation failed:
|
|
51
|
+
${validationResult.errors.join("\n")}`
|
|
26
52
|
);
|
|
27
53
|
}
|
|
54
|
+
return config2;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/utils/client-init.ts
|
|
58
|
+
var config = initializeConfig();
|
|
59
|
+
var clientApp = app.initializeApp(config);
|
|
60
|
+
var auth = auth$1.getAuth(clientApp);
|
|
61
|
+
auth$1.setPersistence(auth, auth$1.browserSessionPersistence);
|
|
62
|
+
firestore.getFirestore(clientApp);
|
|
63
|
+
storage.getStorage(clientApp);
|
|
64
|
+
var TernSecureAuth = () => auth;
|
|
65
|
+
var TernSecureContext = React__default.default.createContext(void 0);
|
|
66
|
+
var useInternalContext = (hookname) => {
|
|
67
|
+
const context = React__default.default.useContext(TernSecureContext);
|
|
28
68
|
return context;
|
|
29
69
|
};
|
|
30
70
|
|
|
31
71
|
// src/boundary/hooks/use-auth.ts
|
|
32
72
|
function useAuth() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
throw new TernSecureError("Authentication context not properly initialized");
|
|
36
|
-
}
|
|
37
|
-
const defaultState = {
|
|
73
|
+
React.useMemo(() => TernSecureAuth(), []);
|
|
74
|
+
const [authState, setAuthState] = React.useState({
|
|
38
75
|
loading: true,
|
|
39
76
|
isSignedIn: false,
|
|
40
77
|
userId: null,
|
|
41
78
|
error: null
|
|
79
|
+
});
|
|
80
|
+
useInternalContext();
|
|
81
|
+
return {
|
|
82
|
+
loading: authState.loading,
|
|
83
|
+
isSignedIn: authState.isSignedIn,
|
|
84
|
+
userId: authState.userId,
|
|
85
|
+
error: authState.error
|
|
42
86
|
};
|
|
43
|
-
return defaultState;
|
|
44
87
|
}
|
|
45
88
|
|
|
46
89
|
exports.useAuth = useAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/boundary/TernSecureCtx.tsx","../../../../src/boundary/hooks/use-auth.ts"],"names":["React"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/config.ts","../../../../src/utils/client-init.ts","../../../../src/boundary/TernSecureCtx.tsx","../../../../src/boundary/hooks/use-auth.ts"],"names":["config","initializeApp","getAuth","setPersistence","browserSessionPersistence","getFirestore","getStorage","React","useMemo","useState"],"mappings":"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","file":"use-auth.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 { useEffect, useState, useMemo } from 'react'\r\nimport { TernSecureAuth } from '../../utils/client-init'\r\nimport { useInternalContext } from '../TernSecureCtx'\r\n\r\nexport interface AuthState {\r\n userId: string | null\r\n loading: boolean;\r\n error: Error | null;\r\n isSignedIn: boolean;\r\n}\r\n\r\nexport function useAuth() {\r\n const auth = useMemo(() => TernSecureAuth(), [])\r\n const [authState, setAuthState] = useState<AuthState>({\r\n loading: true,\r\n isSignedIn: false,\r\n userId: null,\r\n error: null\r\n })\r\n\r\n useInternalContext('useAuth')\r\n return {\r\n loading: authState.loading,\r\n isSignedIn: authState.isSignedIn,\r\n userId: authState.userId,\r\n error: authState.error\r\n }\r\n}"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -6,250 +6,130 @@ var firestore$1 = require('firebase/firestore');
|
|
|
6
6
|
var storage$1 = require('firebase/storage');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
-
var dynamic = require('next/dynamic');
|
|
10
9
|
|
|
11
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
11
|
|
|
13
12
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
14
|
-
var dynamic__default = /*#__PURE__*/_interopDefault(dynamic);
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
18
|
-
var __esm = (fn, res) => function __init() {
|
|
19
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
20
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
22
|
-
for (var name in all)
|
|
23
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
-
};
|
|
14
|
+
// src/utils/client-init.ts
|
|
25
15
|
|
|
26
16
|
// src/utils/config.ts
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || "",
|
|
36
|
-
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "",
|
|
37
|
-
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || void 0
|
|
38
|
-
});
|
|
39
|
-
exports.validateConfig = (config2) => {
|
|
40
|
-
const requiredFields = [
|
|
41
|
-
"apiKey",
|
|
42
|
-
"authDomain",
|
|
43
|
-
"projectId",
|
|
44
|
-
"storageBucket",
|
|
45
|
-
"messagingSenderId",
|
|
46
|
-
"appId"
|
|
47
|
-
];
|
|
48
|
-
const errors = [];
|
|
49
|
-
requiredFields.forEach((field) => {
|
|
50
|
-
if (!config2[field]) {
|
|
51
|
-
errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
isValid: errors.length === 0,
|
|
56
|
-
errors,
|
|
57
|
-
config: config2
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
initializeConfig = () => {
|
|
61
|
-
const config2 = exports.loadFireConfig();
|
|
62
|
-
const validationResult = exports.validateConfig(config2);
|
|
63
|
-
if (!validationResult.isValid) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Firebase configuration validation failed:
|
|
66
|
-
${validationResult.errors.join("\n")}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return config2;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
var config, clientApp, auth, firestore, storage; exports.TernSecureAuth = void 0; exports.TernSecureFirestore = void 0; exports.TernSecureStorage = void 0;
|
|
74
|
-
var init_client_init = __esm({
|
|
75
|
-
"src/utils/client-init.ts"() {
|
|
76
|
-
init_config();
|
|
77
|
-
config = initializeConfig();
|
|
78
|
-
clientApp = app.initializeApp(config);
|
|
79
|
-
auth = auth$1.getAuth(clientApp);
|
|
80
|
-
auth$1.setPersistence(auth, auth$1.browserSessionPersistence);
|
|
81
|
-
firestore = firestore$1.getFirestore(clientApp);
|
|
82
|
-
storage = storage$1.getStorage(clientApp);
|
|
83
|
-
exports.TernSecureAuth = () => auth;
|
|
84
|
-
exports.TernSecureFirestore = () => firestore;
|
|
85
|
-
exports.TernSecureStorage = () => storage;
|
|
86
|
-
}
|
|
17
|
+
var loadFireConfig = () => ({
|
|
18
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || "",
|
|
19
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || "",
|
|
20
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || "",
|
|
21
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || "",
|
|
22
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || "",
|
|
23
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "",
|
|
24
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID || void 0
|
|
87
25
|
});
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"TernSecureCtxProvider must be used in client components"
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
if (process.env.NODE_ENV !== "production") {
|
|
121
|
-
React__default.default.useEffect(() => {
|
|
122
|
-
console.log("[TernSecure] Provider initialized in client component");
|
|
123
|
-
}, []);
|
|
124
|
-
}
|
|
125
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { dynamic: true }, children });
|
|
126
|
-
};
|
|
26
|
+
var validateConfig = (config2) => {
|
|
27
|
+
const requiredFields = [
|
|
28
|
+
"apiKey",
|
|
29
|
+
"authDomain",
|
|
30
|
+
"projectId",
|
|
31
|
+
"storageBucket",
|
|
32
|
+
"messagingSenderId",
|
|
33
|
+
"appId"
|
|
34
|
+
];
|
|
35
|
+
const errors = [];
|
|
36
|
+
requiredFields.forEach((field) => {
|
|
37
|
+
if (!config2[field]) {
|
|
38
|
+
errors.push(`Missing required field: NEXT_PUBLIC_FIREBASE_${String(field).toUpperCase()}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
isValid: errors.length === 0,
|
|
43
|
+
errors,
|
|
44
|
+
config: config2
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var initializeConfig = () => {
|
|
48
|
+
const config2 = loadFireConfig();
|
|
49
|
+
const validationResult = validateConfig(config2);
|
|
50
|
+
if (!validationResult.isValid) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Firebase configuration validation failed:
|
|
53
|
+
${validationResult.errors.join("\n")}`
|
|
54
|
+
);
|
|
127
55
|
}
|
|
128
|
-
|
|
56
|
+
return config2;
|
|
57
|
+
};
|
|
129
58
|
|
|
130
|
-
// src/
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
59
|
+
// src/utils/client-init.ts
|
|
60
|
+
var config = initializeConfig();
|
|
61
|
+
var clientApp = app.initializeApp(config);
|
|
62
|
+
var auth = auth$1.getAuth(clientApp);
|
|
63
|
+
auth$1.setPersistence(auth, auth$1.browserSessionPersistence);
|
|
64
|
+
var firestore = firestore$1.getFirestore(clientApp);
|
|
65
|
+
var storage = storage$1.getStorage(clientApp);
|
|
66
|
+
var TernSecureAuth = () => auth;
|
|
67
|
+
var TernSecureFirestore = () => firestore;
|
|
68
|
+
var TernSecureStorage = () => storage;
|
|
69
|
+
async function signInWithEmail({
|
|
70
|
+
email,
|
|
71
|
+
password
|
|
72
|
+
}) {
|
|
73
|
+
const auth3 = TernSecureAuth();
|
|
74
|
+
return auth$1.signInWithEmailAndPassword(auth3, email, password);
|
|
75
|
+
}
|
|
76
|
+
var TernSecureContext = React__default.default.createContext(void 0);
|
|
77
|
+
var useInternalContext = (hookname) => {
|
|
78
|
+
const context = React__default.default.useContext(TernSecureContext);
|
|
79
|
+
return context;
|
|
80
|
+
};
|
|
81
|
+
var TernSecureCtxProvider = (props) => {
|
|
82
|
+
const { children, options } = props;
|
|
83
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TernSecureContext.Provider, { value: { value: options }, children });
|
|
84
|
+
};
|
|
85
|
+
var auth2 = TernSecureAuth();
|
|
135
86
|
function TernSecureClientProvider({ children }) {
|
|
136
|
-
if (typeof window === "undefined") {
|
|
137
|
-
throw new TernSecureError("TernSecureClientProvider must be used in client components");
|
|
138
|
-
}
|
|
139
87
|
const [authState, setAuthState] = React.useState({
|
|
140
88
|
loading: true,
|
|
141
89
|
isSignedIn: false,
|
|
142
90
|
userId: null,
|
|
143
91
|
error: null
|
|
144
92
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
setAuthState((prev) => ({
|
|
162
|
-
...prev,
|
|
163
|
-
loading: false,
|
|
164
|
-
error: error.message
|
|
165
|
-
}));
|
|
166
|
-
if (process.env.NODE_ENV !== "production") {
|
|
167
|
-
console.error("[TernSecure] Auth state error:", error);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
);
|
|
171
|
-
if (process.env.NODE_ENV !== "production") {
|
|
172
|
-
console.log("[TernSecure] Auth listener established");
|
|
173
|
-
}
|
|
174
|
-
return () => {
|
|
175
|
-
unsubscribe();
|
|
176
|
-
if (process.env.NODE_ENV !== "production") {
|
|
177
|
-
console.log("[TernSecure] Auth listener cleaned up");
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
} catch (error) {
|
|
181
|
-
setAuthState((prev) => ({
|
|
182
|
-
...prev,
|
|
183
|
-
loading: false,
|
|
184
|
-
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
185
|
-
}));
|
|
186
|
-
if (process.env.NODE_ENV !== "production") {
|
|
187
|
-
console.error("[TernSecure] Setup error:", error);
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
const unsubscribe = auth$1.onAuthStateChanged(auth2, (user) => {
|
|
95
|
+
if (user) {
|
|
96
|
+
setAuthState({
|
|
97
|
+
loading: false,
|
|
98
|
+
isSignedIn: true,
|
|
99
|
+
userId: user.uid,
|
|
100
|
+
error: null
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
setAuthState({
|
|
104
|
+
loading: false,
|
|
105
|
+
isSignedIn: false,
|
|
106
|
+
userId: null,
|
|
107
|
+
error: null
|
|
108
|
+
});
|
|
188
109
|
}
|
|
189
|
-
}
|
|
110
|
+
});
|
|
111
|
+
return () => unsubscribe();
|
|
190
112
|
}, []);
|
|
191
|
-
return /* @__PURE__ */ jsxRuntime.jsx(TernSecureCtxProvider, { children });
|
|
113
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TernSecureCtxProvider, { options: authState, children });
|
|
192
114
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
"src/app-router/client/TernSecureProvider.tsx"() {
|
|
196
|
-
"use client";
|
|
197
|
-
init_client_init();
|
|
198
|
-
init_TernSecureCtx();
|
|
199
|
-
auth2 = exports.TernSecureAuth();
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
function TernSecureLoadingFallback() {
|
|
203
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
204
|
-
"div",
|
|
205
|
-
{
|
|
206
|
-
"aria-label": "Loading authentication",
|
|
207
|
-
role: "status",
|
|
208
|
-
className: "tern-secure-loading",
|
|
209
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading authentication..." })
|
|
210
|
-
}
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
var TernSecureClientProvider2 = dynamic__default.default(
|
|
214
|
-
() => Promise.resolve().then(() => (init_TernSecureProvider(), TernSecureProvider_exports)).then((mod) => mod.TernSecureClientProvider),
|
|
215
|
-
{
|
|
216
|
-
loading: TernSecureLoadingFallback
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
function TernSecureServerProvider({
|
|
220
|
-
children
|
|
221
|
-
}) {
|
|
222
|
-
return /* @__PURE__ */ jsxRuntime.jsx(React__default.default.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(TernSecureLoadingFallback, {}), children: /* @__PURE__ */ jsxRuntime.jsx(TernSecureClientProvider2, { children }) });
|
|
115
|
+
function TernSecureProvider({ children }) {
|
|
116
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }), children: /* @__PURE__ */ jsxRuntime.jsx(TernSecureClientProvider, { children }) });
|
|
223
117
|
}
|
|
224
|
-
|
|
225
|
-
// src/index.ts
|
|
226
|
-
init_client_init();
|
|
227
|
-
init_config();
|
|
228
|
-
|
|
229
|
-
// src/app-router/server/auth.ts
|
|
230
|
-
init_client_init();
|
|
231
|
-
async function signInWithEmail({
|
|
232
|
-
email,
|
|
233
|
-
password
|
|
234
|
-
}) {
|
|
235
|
-
const auth3 = exports.TernSecureAuth();
|
|
236
|
-
return auth$1.signInWithEmailAndPassword(auth3, email, password);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/boundary/hooks/use-auth.ts
|
|
240
|
-
init_TernSecureCtx();
|
|
241
118
|
function useAuth() {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
throw new TernSecureError("Authentication context not properly initialized");
|
|
245
|
-
}
|
|
246
|
-
const defaultState = {
|
|
119
|
+
React.useMemo(() => TernSecureAuth(), []);
|
|
120
|
+
const [authState, setAuthState] = React.useState({
|
|
247
121
|
loading: true,
|
|
248
122
|
isSignedIn: false,
|
|
249
123
|
userId: null,
|
|
250
124
|
error: null
|
|
125
|
+
});
|
|
126
|
+
useInternalContext();
|
|
127
|
+
return {
|
|
128
|
+
loading: authState.loading,
|
|
129
|
+
isSignedIn: authState.isSignedIn,
|
|
130
|
+
userId: authState.userId,
|
|
131
|
+
error: authState.error
|
|
251
132
|
};
|
|
252
|
-
return defaultState;
|
|
253
133
|
}
|
|
254
134
|
|
|
255
135
|
// src/utils/create-styles.ts
|
|
@@ -470,12 +350,16 @@ function SignIn({
|
|
|
470
350
|
] });
|
|
471
351
|
}
|
|
472
352
|
|
|
473
|
-
// src/index.ts
|
|
474
|
-
var TernSecureProvider = TernSecureServerProvider;
|
|
475
|
-
|
|
476
353
|
exports.SignIn = SignIn;
|
|
354
|
+
exports.TernSecureAuth = TernSecureAuth;
|
|
355
|
+
exports.TernSecureClientProvider = TernSecureClientProvider;
|
|
356
|
+
exports.TernSecureFirestore = TernSecureFirestore;
|
|
477
357
|
exports.TernSecureProvider = TernSecureProvider;
|
|
358
|
+
exports.TernSecureStorage = TernSecureStorage;
|
|
359
|
+
exports.loadFireConfig = loadFireConfig;
|
|
478
360
|
exports.signInWithEmail = signInWithEmail;
|
|
479
361
|
exports.useAuth = useAuth;
|
|
362
|
+
exports.useInternalContext = useInternalContext;
|
|
363
|
+
exports.validateConfig = validateConfig;
|
|
480
364
|
//# sourceMappingURL=index.cjs.map
|
|
481
365
|
//# sourceMappingURL=index.cjs.map
|