@tern-secure/nextjs 3.1.37 → 3.1.39
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/server/index.js +18 -2
- package/dist/cjs/app-router/server/index.js.map +2 -2
- package/dist/cjs/components/index.js +17 -44
- package/dist/cjs/components/index.js.map +4 -4
- package/dist/cjs/index.js +18 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/app-router/server/index.js +1 -1
- package/dist/esm/app-router/server/providers/TernSecureServerProvider.d.ts.map +1 -1
- package/dist/esm/{chunk-VQBYO2G6.js → chunk-XXCJHKRH.js} +19 -3
- package/dist/esm/chunk-XXCJHKRH.js.map +7 -0
- package/dist/esm/index.js +1 -1
- package/package.json +5 -1
- package/dist/esm/chunk-VQBYO2G6.js.map +0 -7
|
@@ -77,17 +77,33 @@ module.exports = __toCommonJS(server_exports);
|
|
|
77
77
|
var import_react3 = __toESM(require("react"), 1);
|
|
78
78
|
var import_dynamic = __toESM(require("next/dynamic"), 1);
|
|
79
79
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
80
|
+
var LoadingProvider = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
81
|
+
"div",
|
|
82
|
+
{
|
|
83
|
+
"aria-label": "Loading authentication provider...",
|
|
84
|
+
role: "status",
|
|
85
|
+
style: { display: "none" }
|
|
86
|
+
}
|
|
87
|
+
);
|
|
80
88
|
var TernSecureClientProvider2 = (0, import_dynamic.default)(
|
|
81
89
|
() => Promise.resolve().then(() => (init_ternSecureClientProvider(), ternSecureClientProvider_exports)).then((mod) => mod.TernSecureClientProvider),
|
|
82
90
|
{
|
|
83
|
-
ssr: false
|
|
84
|
-
|
|
91
|
+
//ssr: false,
|
|
92
|
+
loading: LoadingProvider
|
|
93
|
+
// Return null or a loading indicator
|
|
85
94
|
}
|
|
86
95
|
);
|
|
87
96
|
function TernSecureProvider({ children }) {
|
|
97
|
+
const startTime = process.env.NODE_ENV === "development" ? performance.now() : 0;
|
|
88
98
|
const isRootLayout = import_react3.default.Children.toArray(children).some(
|
|
89
99
|
(child) => import_react3.default.isValidElement(child) && child.type === "html"
|
|
90
100
|
);
|
|
101
|
+
import_react3.default.useEffect(() => {
|
|
102
|
+
if (process.env.NODE_ENV === "development") {
|
|
103
|
+
const endTime = performance.now();
|
|
104
|
+
console.debug(`TernSecure provider mounted in ${endTime - startTime}ms`);
|
|
105
|
+
}
|
|
106
|
+
}, [startTime]);
|
|
91
107
|
if (isRootLayout) {
|
|
92
108
|
return import_react3.default.Children.map(children, (child) => {
|
|
93
109
|
if (import_react3.default.isValidElement(child) && child.type === "html") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/app-router/client/providers/ternSecureContext.tsx", "../../../../src/app-router/client/providers/ternSecureClientProvider.tsx", "../../../../src/app-router/server/index.ts", "../../../../src/app-router/server/providers/TernSecureServerProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client'\r\n\r\nimport { createContext, useContext } from 'react'\r\n\r\n/**\r\n * Internal context type for TernSecure authentication\r\n * @internal\r\n */\r\ninterface TernSecureContextType {\r\n readonly _contextKey: symbol\r\n}\r\n\r\n/**\r\n * Internal symbol used for context validation\r\n * @internal\r\n */\r\nconst INTERNAL_CONTEXT_KEY = Symbol('TERN_SECURE_CONTEXT')\r\n\r\n/**\r\n * Context for TernSecure authentication\r\n * @internal\r\n */\r\nconst TernSecureContext = createContext<TernSecureContextType | null>(null)\r\n\r\n/**\r\n * Hook to verify that components are rendered within the TernSecure provider\r\n * @param hookName - Name of the hook being used (for better error messages)\r\n * @throws {Error} When used outside of TernSecureProvider\r\n * @internal\r\n */\r\nconst useInternalContext = (hookName?: string): TernSecureContextType => {\r\n const context = useContext(TernSecureContext)\r\n \r\n if (!context || context._contextKey !== INTERNAL_CONTEXT_KEY) {\r\n throw new Error(\r\n `${hookName || 'Hook'} must be used within TernSecureProvider. ` +\r\n 'Please wrap your component with TernSecureProvider.'\r\n )\r\n }\r\n \r\n return context\r\n}\r\n\r\nexport {\r\n type TernSecureContextType,\r\n TernSecureContext,\r\n useInternalContext,\r\n INTERNAL_CONTEXT_KEY\r\n}", "'use client'\r\n\r\nimport React from 'react'\r\nimport { INTERNAL_CONTEXT_KEY, TernSecureContext, TernSecureContextType } from './ternSecureContext'\r\n\r\n/**\r\n * Props for the TernSecureClientProvider component\r\n */\r\ninterface TernSecureClientProviderProps {\r\n /** React child elements to be wrapped by the provider */\r\n children: React.ReactNode\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure authentication\r\n * Must be used to wrap any components that use TernSecure hooks\r\n * \r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * return (\r\n * <TernSecureClientProvider>\r\n * <YourApp />\r\n * </TernSecureClientProvider>\r\n * )\r\n * }\r\n * ```\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProviderProps): JSX.Element {\r\n // Memoize the context value to prevent unnecessary re-renders\r\n const contextValue = React.useMemo<TernSecureContextType>(\r\n () => ({ _contextKey: INTERNAL_CONTEXT_KEY }),\r\n []\r\n )\r\n\r\n return (\r\n <TernSecureContext.Provider value={contextValue}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\n// Add display name for better debugging\r\nTernSecureClientProvider.displayName = 'TernSecureClientProvider'", "export { TernSecureProvider } from './providers/TernSecureServerProvider';", "import React, { ReactNode } from 'react';\r\nimport dynamic from 'next/dynamic'\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\n// Dynamically import the client provider with no SSR\r\nconst TernSecureClientProvider = dynamic(\r\n () => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n ssr: false
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAEA,cAcM,sBAMA;AAtBN;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAc1C,IAAM,uBAAuB,OAAO,qBAAqB;AAMzD,IAAM,wBAAoB,4BAA4C,IAAI;AAAA;AAAA;;;ACtB1E;AAAA;AAAA;AAAA;AA4BO,SAAS,yBAAyB,EAAE,SAAS,GAA+C;AAEjG,QAAM,eAAe,cAAAA,QAAM;AAAA,IACzB,OAAO,EAAE,aAAa,qBAAqB;AAAA,IAC3C,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,kBAAkB,UAAlB,EAA2B,OAAO,cAChC,UACH;AAEJ;AAxCA,IAEAC,eAkCI;AApCJ;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAAkB;AAClB;AAiCI;AAOJ,6BAAyB,cAAc;AAAA;AAAA;;;AC3CvC;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAC,gBAAiC;AACjC,qBAAoB;
|
|
4
|
+
"sourcesContent": ["'use client'\r\n\r\nimport { createContext, useContext } from 'react'\r\n\r\n/**\r\n * Internal context type for TernSecure authentication\r\n * @internal\r\n */\r\ninterface TernSecureContextType {\r\n readonly _contextKey: symbol\r\n}\r\n\r\n/**\r\n * Internal symbol used for context validation\r\n * @internal\r\n */\r\nconst INTERNAL_CONTEXT_KEY = Symbol('TERN_SECURE_CONTEXT')\r\n\r\n/**\r\n * Context for TernSecure authentication\r\n * @internal\r\n */\r\nconst TernSecureContext = createContext<TernSecureContextType | null>(null)\r\n\r\n/**\r\n * Hook to verify that components are rendered within the TernSecure provider\r\n * @param hookName - Name of the hook being used (for better error messages)\r\n * @throws {Error} When used outside of TernSecureProvider\r\n * @internal\r\n */\r\nconst useInternalContext = (hookName?: string): TernSecureContextType => {\r\n const context = useContext(TernSecureContext)\r\n \r\n if (!context || context._contextKey !== INTERNAL_CONTEXT_KEY) {\r\n throw new Error(\r\n `${hookName || 'Hook'} must be used within TernSecureProvider. ` +\r\n 'Please wrap your component with TernSecureProvider.'\r\n )\r\n }\r\n \r\n return context\r\n}\r\n\r\nexport {\r\n type TernSecureContextType,\r\n TernSecureContext,\r\n useInternalContext,\r\n INTERNAL_CONTEXT_KEY\r\n}", "'use client'\r\n\r\nimport React from 'react'\r\nimport { INTERNAL_CONTEXT_KEY, TernSecureContext, TernSecureContextType } from './ternSecureContext'\r\n\r\n/**\r\n * Props for the TernSecureClientProvider component\r\n */\r\ninterface TernSecureClientProviderProps {\r\n /** React child elements to be wrapped by the provider */\r\n children: React.ReactNode\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure authentication\r\n * Must be used to wrap any components that use TernSecure hooks\r\n * \r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * return (\r\n * <TernSecureClientProvider>\r\n * <YourApp />\r\n * </TernSecureClientProvider>\r\n * )\r\n * }\r\n * ```\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProviderProps): JSX.Element {\r\n // Memoize the context value to prevent unnecessary re-renders\r\n const contextValue = React.useMemo<TernSecureContextType>(\r\n () => ({ _contextKey: INTERNAL_CONTEXT_KEY }),\r\n []\r\n )\r\n\r\n return (\r\n <TernSecureContext.Provider value={contextValue}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\n// Add display name for better debugging\r\nTernSecureClientProvider.displayName = 'TernSecureClientProvider'", "export { TernSecureProvider } from './providers/TernSecureServerProvider';", "import React, { ReactNode } from 'react';\r\nimport dynamic from 'next/dynamic'\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\n// Lightweight loading component\r\nconst LoadingProvider = () => (\r\n <div \r\n aria-label=\"Loading authentication provider...\" \r\n role=\"status\"\r\n style={{ display: 'none' }}\r\n />\r\n)\r\n\r\n// Dynamically import the client provider with no SSR\r\nconst TernSecureClientProvider = dynamic(\r\n () => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n //ssr: false,\r\n loading: LoadingProvider // Return null or a loading indicator\r\n }\r\n)\r\n\r\nexport function TernSecureProvider({ children }: TernSecureProviderProps) {\r\n const startTime = process.env.NODE_ENV === 'development' ? performance.now() : 0\r\n\r\n // Check if the children contain html/body tags\r\n const isRootLayout = React.Children.toArray(children).some(\r\n child => React.isValidElement(child) && child.type === 'html'\r\n );\r\n\r\n // Log performance in development\r\n React.useEffect(() => {\r\n if (process.env.NODE_ENV === 'development') {\r\n const endTime = performance.now()\r\n console.debug(`TernSecure provider mounted in ${endTime - startTime}ms`)\r\n }\r\n }, [startTime])\r\n\r\n if (isRootLayout) {\r\n // If this is the root layout, inject our provider after the body tag\r\n return React.Children.map(children, child => {\r\n if (React.isValidElement(child) && child.type === 'html') {\r\n return React.cloneElement(child, {}, \r\n React.Children.map(child.props.children, bodyChild => {\r\n if (React.isValidElement(bodyChild) && bodyChild.type === 'body') {\r\n // Type assertion to access props safely\r\n const bodyProps = bodyChild.props as { children: ReactNode };\r\n return React.cloneElement(bodyChild, {}, \r\n <TernSecureClientProvider>\r\n {bodyProps.children}\r\n </TernSecureClientProvider>\r\n );\r\n }\r\n return bodyChild;\r\n })\r\n );\r\n }\r\n return child;\r\n });\r\n }\r\n\r\n // For non-root layouts, wrap normally\r\n return <TernSecureClientProvider>{children}</TernSecureClientProvider>;\r\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAEA,cAcM,sBAMA;AAtBN;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAc1C,IAAM,uBAAuB,OAAO,qBAAqB;AAMzD,IAAM,wBAAoB,4BAA4C,IAAI;AAAA;AAAA;;;ACtB1E;AAAA;AAAA;AAAA;AA4BO,SAAS,yBAAyB,EAAE,SAAS,GAA+C;AAEjG,QAAM,eAAe,cAAAA,QAAM;AAAA,IACzB,OAAO,EAAE,aAAa,qBAAqB;AAAA,IAC3C,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,kBAAkB,UAAlB,EAA2B,OAAO,cAChC,UACH;AAEJ;AAxCA,IAEAC,eAkCI;AApCJ;AAAA;AAAA;AAAA;AAEA,IAAAA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A,gBAAW,CAAC;AAAA,gBACpC,6CAACF,2BAAA,EACE,oBAAU,UACb;AAAA,cACF;AAAA,YACF;AACA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAGA,SAAO,6CAACA,2BAAA,EAA0B,UAAS;AAC7C;",
|
|
6
6
|
"names": ["React", "import_react", "import_react", "import_jsx_runtime", "TernSecureClientProvider", "dynamic", "React"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/components/index.ts
|
|
@@ -35,7 +25,7 @@ __export(components_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(components_exports);
|
|
36
26
|
|
|
37
27
|
// src/components/sign-in.tsx
|
|
38
|
-
var
|
|
28
|
+
var import_react = require("react");
|
|
39
29
|
|
|
40
30
|
// src/app-router/client/client-init.ts
|
|
41
31
|
var import_app = require("firebase/app");
|
|
@@ -83,23 +73,6 @@ async function signInWithEmail({
|
|
|
83
73
|
return (0, import_auth2.signInWithEmailAndPassword)(auth2, email, password);
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
// src/app-router/client/providers/ternSecureContext.tsx
|
|
87
|
-
var import_react = require("react");
|
|
88
|
-
var INTERNAL_CONTEXT_KEY = Symbol("TERN_SECURE_CONTEXT");
|
|
89
|
-
var TernSecureContext = (0, import_react.createContext)(null);
|
|
90
|
-
|
|
91
|
-
// src/app-router/client/providers/ternSecureClientProvider.tsx
|
|
92
|
-
var import_react2 = __toESM(require("react"), 1);
|
|
93
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
94
|
-
function TernSecureClientProvider({ children }) {
|
|
95
|
-
const contextValue = import_react2.default.useMemo(
|
|
96
|
-
() => ({ _contextKey: INTERNAL_CONTEXT_KEY }),
|
|
97
|
-
[]
|
|
98
|
-
);
|
|
99
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TernSecureContext.Provider, { value: contextValue, children });
|
|
100
|
-
}
|
|
101
|
-
TernSecureClientProvider.displayName = "TernSecureClientProvider";
|
|
102
|
-
|
|
103
76
|
// src/utils/create-styles.ts
|
|
104
77
|
var PREFIX = "tern";
|
|
105
78
|
var styleInjection = {
|
|
@@ -219,7 +192,7 @@ var styleConfig = {
|
|
|
219
192
|
var styles = createStyleSheet(styleConfig);
|
|
220
193
|
|
|
221
194
|
// src/components/sign-in.tsx
|
|
222
|
-
var
|
|
195
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
223
196
|
function SignIn({
|
|
224
197
|
onSuccess,
|
|
225
198
|
onError,
|
|
@@ -228,10 +201,10 @@ function SignIn({
|
|
|
228
201
|
style,
|
|
229
202
|
customStyles = {}
|
|
230
203
|
}) {
|
|
231
|
-
const [email, setEmail] = (0,
|
|
232
|
-
const [password, setPassword] = (0,
|
|
233
|
-
const [loading, setLoading] = (0,
|
|
234
|
-
const [error, setError] = (0,
|
|
204
|
+
const [email, setEmail] = (0, import_react.useState)("");
|
|
205
|
+
const [password, setPassword] = (0, import_react.useState)("");
|
|
206
|
+
const [loading, setLoading] = (0, import_react.useState)(false);
|
|
207
|
+
const [error, setError] = (0, import_react.useState)("");
|
|
235
208
|
const handleSubmit = async (e) => {
|
|
236
209
|
e.preventDefault();
|
|
237
210
|
setLoading(true);
|
|
@@ -250,9 +223,9 @@ function SignIn({
|
|
|
250
223
|
setLoading(false);
|
|
251
224
|
}
|
|
252
225
|
};
|
|
253
|
-
return /* @__PURE__ */ (0,
|
|
254
|
-
/* @__PURE__ */ (0,
|
|
255
|
-
/* @__PURE__ */ (0,
|
|
226
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `${styles.container} ${customStyles.container || ""}`, style, children: [
|
|
227
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `${styles.header} ${customStyles.header || ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: `${styles.title} ${customStyles.title || ""}`, children: "Sign in to your account" }) }),
|
|
228
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `${styles.formWrapper} ${customStyles.formWrapper || ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `${styles.formContainer} ${customStyles.formContainer || ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
256
229
|
"form",
|
|
257
230
|
{
|
|
258
231
|
onSubmit: handleSubmit,
|
|
@@ -260,7 +233,7 @@ function SignIn({
|
|
|
260
233
|
role: "form",
|
|
261
234
|
"aria-label": "Sign in form",
|
|
262
235
|
children: [
|
|
263
|
-
error && /* @__PURE__ */ (0,
|
|
236
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
264
237
|
"div",
|
|
265
238
|
{
|
|
266
239
|
className: `${styles.error} ${customStyles.errorText || ""}`,
|
|
@@ -269,9 +242,9 @@ function SignIn({
|
|
|
269
242
|
children: error
|
|
270
243
|
}
|
|
271
244
|
),
|
|
272
|
-
/* @__PURE__ */ (0,
|
|
273
|
-
/* @__PURE__ */ (0,
|
|
274
|
-
/* @__PURE__ */ (0,
|
|
245
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
246
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: "email", className: `${styles.label} ${customStyles.label || ""}`, children: "Email" }),
|
|
247
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
275
248
|
"input",
|
|
276
249
|
{
|
|
277
250
|
id: "email",
|
|
@@ -287,9 +260,9 @@ function SignIn({
|
|
|
287
260
|
}
|
|
288
261
|
)
|
|
289
262
|
] }),
|
|
290
|
-
/* @__PURE__ */ (0,
|
|
291
|
-
/* @__PURE__ */ (0,
|
|
292
|
-
/* @__PURE__ */ (0,
|
|
263
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
264
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: "password", className: `${styles.label} ${customStyles.label || ""}`, children: "Password" }),
|
|
265
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
293
266
|
"input",
|
|
294
267
|
{
|
|
295
268
|
id: "password",
|
|
@@ -305,7 +278,7 @@ function SignIn({
|
|
|
305
278
|
}
|
|
306
279
|
)
|
|
307
280
|
] }),
|
|
308
|
-
/* @__PURE__ */ (0,
|
|
281
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
309
282
|
"button",
|
|
310
283
|
{
|
|
311
284
|
type: "submit",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/index.ts", "../../../src/components/sign-in.tsx", "../../../src/app-router/client/client-init.ts", "../../../src/app-router/client/config.ts", "../../../src/app-router/client/auth.ts", "../../../src/
|
|
4
|
-
"sourcesContent": ["export { SignIn } from './sign-in';", "import * as React from 'react'\r\nimport { useState } from 'react'\r\nimport { signInWithEmail } from '../app-router/client'\r\nimport { styles } from '../utils/create-styles'\r\n\r\nexport interface SignInProps {\r\n onSuccess?: () => void\r\n onError?: (error: Error) => void\r\n redirectUrl?: string\r\n className?: string\r\n style?: React.CSSProperties\r\n customStyles?: {\r\n container?: string\r\n header?: string\r\n title?: string\r\n formWrapper?: string\r\n formContainer?: string\r\n form?: string\r\n input?: string\r\n button?: string\r\n errorText?: string\r\n label?: string\r\n }\r\n}\r\n\r\nexport function SignIn({ \r\n onSuccess, \r\n onError, \r\n redirectUrl,\r\n className = '',\r\n style,\r\n customStyles = {}\r\n}: SignInProps) {\r\n const [email, setEmail] = useState('')\r\n const [password, setPassword] = useState('')\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState('')\r\n\r\n const handleSubmit = async (e: React.FormEvent) => {\r\n e.preventDefault()\r\n setLoading(true)\r\n setError('')\r\n\r\n try {\r\n await signInWithEmail({ email, password })\r\n onSuccess?.()\r\n \r\n if (redirectUrl) {\r\n window.location.href = redirectUrl\r\n }\r\n } catch (err) {\r\n const errorMessage = err instanceof Error ? err.message : 'Failed to sign in'\r\n setError(errorMessage)\r\n onError?.(err instanceof Error ? err : new Error('Failed to sign in'))\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n return (\r\n <div className={`${styles.container} ${customStyles.container || ''}`} style={style}>\r\n <div className={`${styles.header} ${customStyles.header || ''}`}>\r\n <h2 className={`${styles.title} ${customStyles.title || ''}`}>\r\n Sign in to your account\r\n </h2>\r\n </div>\r\n \r\n <div className={`${styles.formWrapper} ${customStyles.formWrapper || ''}`}>\r\n <div className={`${styles.formContainer} ${customStyles.formContainer || ''}`}>\r\n <form \r\n onSubmit={handleSubmit} \r\n className={`${styles.form} ${customStyles.form || ''} ${className}`}\r\n role=\"form\"\r\n aria-label=\"Sign in form\"\r\n >\r\n {error && (\r\n <div \r\n className={`${styles.error} ${customStyles.errorText || ''}`}\r\n role=\"alert\"\r\n aria-live=\"polite\"\r\n >\r\n {error}\r\n </div>\r\n )}\r\n <div>\r\n <label htmlFor=\"email\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Email\r\n </label>\r\n <input\r\n id=\"email\"\r\n type=\"email\"\r\n value={email}\r\n onChange={(e) => setEmail(e.target.value)}\r\n placeholder=\"Enter your email\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <div>\r\n <label htmlFor=\"password\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Password\r\n </label>\r\n <input\r\n id=\"password\"\r\n type=\"password\"\r\n value={password}\r\n onChange={(e) => setPassword(e.target.value)}\r\n placeholder=\"Enter your password\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <button \r\n type=\"submit\" \r\n disabled={loading}\r\n className={`${styles.button} ${customStyles.button || ''}`}\r\n data-testid=\"sign-in-submit\"\r\n >\r\n {loading ? 'Signing in...' : 'Sign in'}\r\n </button>\r\n </form>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\n", "import { getApps, 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 { loadFireConfig, validateConfig } from './config';\r\n\r\n// Initialize immediately\r\nconst app = (() => {\r\n const config = validateConfig(loadFireConfig());\r\n return getApps().length ? getApps()[0] : initializeApp(config);\r\n})();\r\n\r\nconst auth = getAuth(app);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(app);\r\nconst storage = getStorage(app);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;", "import { TernSecureConfig } from \"../../types\";\r\n\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY as string,\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN as string,\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID as string,\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET as string,\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID as string,\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID as string,\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID as string,\r\n});\r\n\r\nexport const validateConfig = (config: TernSecureConfig): TernSecureConfig => {\r\n Object.entries(config).forEach(([key, value]) => {\r\n if (!value) {\r\n throw new Error(`Missing environment variable: NEXT_PUBLIC_FIREBASE_${key.toUpperCase()}`);\r\n }\r\n });\r\n return config;\r\n};", "import { TernSecureAuth } from './index'\r\nimport { signInWithEmailAndPassword, type UserCredential } from 'firebase/auth'\r\n\r\nexport interface SignInCredentials {\r\n email: string\r\n password: string\r\n}\r\n\r\nexport async function signInWithEmail({ \r\n email, \r\n password \r\n}: SignInCredentials): Promise<UserCredential> {\r\n const auth = TernSecureAuth()\r\n return signInWithEmailAndPassword(auth, email, password)\r\n} ", "'use client'\r\n\r\nimport { createContext, useContext } from 'react'\r\n\r\n/**\r\n * Internal context type for TernSecure authentication\r\n * @internal\r\n */\r\ninterface TernSecureContextType {\r\n readonly _contextKey: symbol\r\n}\r\n\r\n/**\r\n * Internal symbol used for context validation\r\n * @internal\r\n */\r\nconst INTERNAL_CONTEXT_KEY = Symbol('TERN_SECURE_CONTEXT')\r\n\r\n/**\r\n * Context for TernSecure authentication\r\n * @internal\r\n */\r\nconst TernSecureContext = createContext<TernSecureContextType | null>(null)\r\n\r\n/**\r\n * Hook to verify that components are rendered within the TernSecure provider\r\n * @param hookName - Name of the hook being used (for better error messages)\r\n * @throws {Error} When used outside of TernSecureProvider\r\n * @internal\r\n */\r\nconst useInternalContext = (hookName?: string): TernSecureContextType => {\r\n const context = useContext(TernSecureContext)\r\n \r\n if (!context || context._contextKey !== INTERNAL_CONTEXT_KEY) {\r\n throw new Error(\r\n `${hookName || 'Hook'} must be used within TernSecureProvider. ` +\r\n 'Please wrap your component with TernSecureProvider.'\r\n )\r\n }\r\n \r\n return context\r\n}\r\n\r\nexport {\r\n type TernSecureContextType,\r\n TernSecureContext,\r\n useInternalContext,\r\n INTERNAL_CONTEXT_KEY\r\n}", "'use client'\r\n\r\nimport React from 'react'\r\nimport { INTERNAL_CONTEXT_KEY, TernSecureContext, TernSecureContextType } from './ternSecureContext'\r\n\r\n/**\r\n * Props for the TernSecureClientProvider component\r\n */\r\ninterface TernSecureClientProviderProps {\r\n /** React child elements to be wrapped by the provider */\r\n children: React.ReactNode\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure authentication\r\n * Must be used to wrap any components that use TernSecure hooks\r\n * \r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * return (\r\n * <TernSecureClientProvider>\r\n * <YourApp />\r\n * </TernSecureClientProvider>\r\n * )\r\n * }\r\n * ```\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProviderProps): JSX.Element {\r\n // Memoize the context value to prevent unnecessary re-renders\r\n const contextValue = React.useMemo<TernSecureContextType>(\r\n () => ({ _contextKey: INTERNAL_CONTEXT_KEY }),\r\n []\r\n )\r\n\r\n return (\r\n <TernSecureContext.Provider value={contextValue}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\n// Add display name for better debugging\r\nTernSecureClientProvider.displayName = 'TernSecureClientProvider'", "'use client'\r\n\r\nconst PREFIX = 'tern'\r\n\r\n// Singleton to track style injection\r\nconst styleInjection = {\r\n isInjected: false,\r\n styleElement: null as HTMLStyleElement | null\r\n}\r\n\r\nexport const defaultClassNames = {\r\n container: `${PREFIX}-container`,\r\n header: `${PREFIX}-header`,\r\n title: `${PREFIX}-title`,\r\n formWrapper: `${PREFIX}-formWrapper`,\r\n formContainer: `${PREFIX}-formContainer`,\r\n form: `${PREFIX}-form`,\r\n label: `${PREFIX}-label`,\r\n input: `${PREFIX}-input`,\r\n button: `${PREFIX}-button`,\r\n error: `${PREFIX}-error`\r\n} as const\r\n\r\n// Create styles once and cache them\r\nfunction createStyleSheet(styles: Record<string, React.CSSProperties>) {\r\n if (typeof window === 'undefined') return defaultClassNames\r\n\r\n // Return early if styles are already injected\r\n if (styleInjection.isInjected) {\r\n return defaultClassNames\r\n }\r\n\r\n // Find existing style element or create new one\r\n let styleElement = document.querySelector<HTMLStyleElement>('[data-tern-secure]')\r\n \r\n if (!styleElement) {\r\n styleElement = document.createElement('style')\r\n styleElement.setAttribute('data-tern-secure', '')\r\n document.head.appendChild(styleElement)\r\n styleInjection.styleElement = styleElement\r\n }\r\n\r\n // Create CSS rules\r\n const cssRules = Object.entries(styles).map(([key, rules]) => {\r\n const className = defaultClassNames[key as keyof typeof defaultClassNames]\r\n const cssProperties = Object.entries(rules).map(([prop, value]) => {\r\n const cssProperty = prop.replace(/([A-Z])/g, '-$1').toLowerCase()\r\n return `${cssProperty}: ${value};`\r\n }).join(' ')\r\n\r\n return `.${className} { ${cssProperties} }`\r\n }).join('\\n')\r\n\r\n // Insert styles only once\r\n styleElement.textContent = cssRules\r\n styleInjection.isInjected = true\r\n\r\n return defaultClassNames\r\n}\r\n\r\n// Style configuration\r\nexport const styleConfig = {\r\n container: {\r\n display: 'flex',\r\n minHeight: '100%',\r\n flex: '1',\r\n flexDirection: 'column',\r\n justifyContent: 'center',\r\n padding: '3rem 1.5rem'\r\n },\r\n header: {\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '28rem'\r\n },\r\n title: {\r\n marginTop: '1.5rem',\r\n textAlign: 'center',\r\n fontSize: '1.875rem',\r\n fontWeight: '700',\r\n lineHeight: '2.25rem',\r\n letterSpacing: '-0.025em',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n formWrapper: {\r\n marginTop: '2.5rem',\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '30rem'\r\n },\r\n formContainer: {\r\n padding: '3rem 1.5rem',\r\n boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)',\r\n borderRadius: '0.5rem',\r\n backgroundColor: 'var(--tern-background, white)'\r\n },\r\n form: {\r\n display: 'flex',\r\n flexDirection: 'column',\r\n gap: '1rem'\r\n },\r\n label: {\r\n display: 'block',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'var(--tern-text-secondary, #374151)'\r\n },\r\n input: {\r\n marginTop: '0.25rem',\r\n display: 'block',\r\n width: '100%',\r\n padding: '0.5rem 0.75rem',\r\n borderRadius: '0.375rem',\r\n border: '1px solid var(--tern-border, #D1D5DB)',\r\n backgroundColor: 'var(--tern-input-background, white)',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n button: {\r\n display: 'flex',\r\n width: '100%',\r\n justifyContent: 'center',\r\n padding: '0.5rem 1rem',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'white',\r\n backgroundColor: 'var(--tern-primary, #2563EB)',\r\n border: 'none',\r\n borderRadius: '0.375rem',\r\n cursor: 'pointer'\r\n },\r\n error: {\r\n color: 'var(--tern-error, #DC2626)',\r\n fontSize: '0.875rem'\r\n }\r\n} as const\r\n\r\n// Export pre-created styles\r\nexport const styles = createStyleSheet(styleConfig)\r\n\r\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/components/index.ts", "../../../src/components/sign-in.tsx", "../../../src/app-router/client/client-init.ts", "../../../src/app-router/client/config.ts", "../../../src/app-router/client/auth.ts", "../../../src/utils/create-styles.ts"],
|
|
4
|
+
"sourcesContent": ["export { SignIn } from './sign-in';", "import * as React from 'react'\r\nimport { useState } from 'react'\r\nimport { signInWithEmail } from '../app-router/client'\r\nimport { styles } from '../utils/create-styles'\r\n\r\nexport interface SignInProps {\r\n onSuccess?: () => void\r\n onError?: (error: Error) => void\r\n redirectUrl?: string\r\n className?: string\r\n style?: React.CSSProperties\r\n customStyles?: {\r\n container?: string\r\n header?: string\r\n title?: string\r\n formWrapper?: string\r\n formContainer?: string\r\n form?: string\r\n input?: string\r\n button?: string\r\n errorText?: string\r\n label?: string\r\n }\r\n}\r\n\r\nexport function SignIn({ \r\n onSuccess, \r\n onError, \r\n redirectUrl,\r\n className = '',\r\n style,\r\n customStyles = {}\r\n}: SignInProps) {\r\n const [email, setEmail] = useState('')\r\n const [password, setPassword] = useState('')\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState('')\r\n\r\n const handleSubmit = async (e: React.FormEvent) => {\r\n e.preventDefault()\r\n setLoading(true)\r\n setError('')\r\n\r\n try {\r\n await signInWithEmail({ email, password })\r\n onSuccess?.()\r\n \r\n if (redirectUrl) {\r\n window.location.href = redirectUrl\r\n }\r\n } catch (err) {\r\n const errorMessage = err instanceof Error ? err.message : 'Failed to sign in'\r\n setError(errorMessage)\r\n onError?.(err instanceof Error ? err : new Error('Failed to sign in'))\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n return (\r\n <div className={`${styles.container} ${customStyles.container || ''}`} style={style}>\r\n <div className={`${styles.header} ${customStyles.header || ''}`}>\r\n <h2 className={`${styles.title} ${customStyles.title || ''}`}>\r\n Sign in to your account\r\n </h2>\r\n </div>\r\n \r\n <div className={`${styles.formWrapper} ${customStyles.formWrapper || ''}`}>\r\n <div className={`${styles.formContainer} ${customStyles.formContainer || ''}`}>\r\n <form \r\n onSubmit={handleSubmit} \r\n className={`${styles.form} ${customStyles.form || ''} ${className}`}\r\n role=\"form\"\r\n aria-label=\"Sign in form\"\r\n >\r\n {error && (\r\n <div \r\n className={`${styles.error} ${customStyles.errorText || ''}`}\r\n role=\"alert\"\r\n aria-live=\"polite\"\r\n >\r\n {error}\r\n </div>\r\n )}\r\n <div>\r\n <label htmlFor=\"email\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Email\r\n </label>\r\n <input\r\n id=\"email\"\r\n type=\"email\"\r\n value={email}\r\n onChange={(e) => setEmail(e.target.value)}\r\n placeholder=\"Enter your email\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <div>\r\n <label htmlFor=\"password\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Password\r\n </label>\r\n <input\r\n id=\"password\"\r\n type=\"password\"\r\n value={password}\r\n onChange={(e) => setPassword(e.target.value)}\r\n placeholder=\"Enter your password\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <button \r\n type=\"submit\" \r\n disabled={loading}\r\n className={`${styles.button} ${customStyles.button || ''}`}\r\n data-testid=\"sign-in-submit\"\r\n >\r\n {loading ? 'Signing in...' : 'Sign in'}\r\n </button>\r\n </form>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\n", "import { getApps, 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 { loadFireConfig, validateConfig } from './config';\r\n\r\n// Initialize immediately\r\nconst app = (() => {\r\n const config = validateConfig(loadFireConfig());\r\n return getApps().length ? getApps()[0] : initializeApp(config);\r\n})();\r\n\r\nconst auth = getAuth(app);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(app);\r\nconst storage = getStorage(app);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;", "import { TernSecureConfig } from \"../../types\";\r\n\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY as string,\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN as string,\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID as string,\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET as string,\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID as string,\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID as string,\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID as string,\r\n});\r\n\r\nexport const validateConfig = (config: TernSecureConfig): TernSecureConfig => {\r\n Object.entries(config).forEach(([key, value]) => {\r\n if (!value) {\r\n throw new Error(`Missing environment variable: NEXT_PUBLIC_FIREBASE_${key.toUpperCase()}`);\r\n }\r\n });\r\n return config;\r\n};", "import { TernSecureAuth } from './index'\r\nimport { signInWithEmailAndPassword, type UserCredential } from 'firebase/auth'\r\n\r\nexport interface SignInCredentials {\r\n email: string\r\n password: string\r\n}\r\n\r\nexport async function signInWithEmail({ \r\n email, \r\n password \r\n}: SignInCredentials): Promise<UserCredential> {\r\n const auth = TernSecureAuth()\r\n return signInWithEmailAndPassword(auth, email, password)\r\n} ", "'use client'\r\n\r\nconst PREFIX = 'tern'\r\n\r\n// Singleton to track style injection\r\nconst styleInjection = {\r\n isInjected: false,\r\n styleElement: null as HTMLStyleElement | null\r\n}\r\n\r\nexport const defaultClassNames = {\r\n container: `${PREFIX}-container`,\r\n header: `${PREFIX}-header`,\r\n title: `${PREFIX}-title`,\r\n formWrapper: `${PREFIX}-formWrapper`,\r\n formContainer: `${PREFIX}-formContainer`,\r\n form: `${PREFIX}-form`,\r\n label: `${PREFIX}-label`,\r\n input: `${PREFIX}-input`,\r\n button: `${PREFIX}-button`,\r\n error: `${PREFIX}-error`\r\n} as const\r\n\r\n// Create styles once and cache them\r\nfunction createStyleSheet(styles: Record<string, React.CSSProperties>) {\r\n if (typeof window === 'undefined') return defaultClassNames\r\n\r\n // Return early if styles are already injected\r\n if (styleInjection.isInjected) {\r\n return defaultClassNames\r\n }\r\n\r\n // Find existing style element or create new one\r\n let styleElement = document.querySelector<HTMLStyleElement>('[data-tern-secure]')\r\n \r\n if (!styleElement) {\r\n styleElement = document.createElement('style')\r\n styleElement.setAttribute('data-tern-secure', '')\r\n document.head.appendChild(styleElement)\r\n styleInjection.styleElement = styleElement\r\n }\r\n\r\n // Create CSS rules\r\n const cssRules = Object.entries(styles).map(([key, rules]) => {\r\n const className = defaultClassNames[key as keyof typeof defaultClassNames]\r\n const cssProperties = Object.entries(rules).map(([prop, value]) => {\r\n const cssProperty = prop.replace(/([A-Z])/g, '-$1').toLowerCase()\r\n return `${cssProperty}: ${value};`\r\n }).join(' ')\r\n\r\n return `.${className} { ${cssProperties} }`\r\n }).join('\\n')\r\n\r\n // Insert styles only once\r\n styleElement.textContent = cssRules\r\n styleInjection.isInjected = true\r\n\r\n return defaultClassNames\r\n}\r\n\r\n// Style configuration\r\nexport const styleConfig = {\r\n container: {\r\n display: 'flex',\r\n minHeight: '100%',\r\n flex: '1',\r\n flexDirection: 'column',\r\n justifyContent: 'center',\r\n padding: '3rem 1.5rem'\r\n },\r\n header: {\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '28rem'\r\n },\r\n title: {\r\n marginTop: '1.5rem',\r\n textAlign: 'center',\r\n fontSize: '1.875rem',\r\n fontWeight: '700',\r\n lineHeight: '2.25rem',\r\n letterSpacing: '-0.025em',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n formWrapper: {\r\n marginTop: '2.5rem',\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '30rem'\r\n },\r\n formContainer: {\r\n padding: '3rem 1.5rem',\r\n boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)',\r\n borderRadius: '0.5rem',\r\n backgroundColor: 'var(--tern-background, white)'\r\n },\r\n form: {\r\n display: 'flex',\r\n flexDirection: 'column',\r\n gap: '1rem'\r\n },\r\n label: {\r\n display: 'block',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'var(--tern-text-secondary, #374151)'\r\n },\r\n input: {\r\n marginTop: '0.25rem',\r\n display: 'block',\r\n width: '100%',\r\n padding: '0.5rem 0.75rem',\r\n borderRadius: '0.375rem',\r\n border: '1px solid var(--tern-border, #D1D5DB)',\r\n backgroundColor: 'var(--tern-input-background, white)',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n button: {\r\n display: 'flex',\r\n width: '100%',\r\n justifyContent: 'center',\r\n padding: '0.5rem 1rem',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'white',\r\n backgroundColor: 'var(--tern-primary, #2563EB)',\r\n border: 'none',\r\n borderRadius: '0.375rem',\r\n cursor: 'pointer'\r\n },\r\n error: {\r\n color: 'var(--tern-error, #DC2626)',\r\n fontSize: '0.875rem'\r\n }\r\n} as const\r\n\r\n// Export pre-created styles\r\nexport const styles = createStyleSheet(styleConfig)\r\n\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAAyB;;;ACDzB,iBAAuC;AACvC,kBAAmE;AACnE,uBAA6B;AAC7B,qBAA2B;;;ACDpB,IAAM,iBAAiB,OAAyB;AAAA,EACrD,QAAQ,QAAQ,IAAI;AAAA,EACpB,YAAY,QAAQ,IAAI;AAAA,EACxB,WAAW,QAAQ,IAAI;AAAA,EACvB,eAAe,QAAQ,IAAI;AAAA,EAC3B,mBAAmB,QAAQ,IAAI;AAAA,EAC/B,OAAO,QAAQ,IAAI;A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Aa,SAAS,EAAE;AAAA,gBACtD,UAAU;AAAA,gBACV,iBAAc;AAAA,gBACd,gBAAc,CAAC,CAAC;AAAA;AAAA,YAClB;AAAA,aACF;AAAA,UACA,6CAAC,SACC;AAAA,wDAAC,WAAM,SAAQ,YAAW,WAAW,GAAG,OAAO,KAAK,IAAI,aAAa,SAAS,EAAE,IAAI,sBAEpF;AAAA,YACA;AAAA,cAAC;AAAA;AAAA,gBACC,IAAG;AAAA,gBACH,MAAK;AAAA,gBACL,OAAO;AAAA,gBACP,UAAU,CAAC,MAAM,YAAY,EAAE,OAAO,KAAK;AAAA,gBAC3C,aAAY;AAAA,gBACZ,UAAQ;AAAA,gBACR,WAAW,GAAG,OAAO,KAAK,IAAI,aAAa,SAAS,EAAE;AAAA,gBACtD,UAAU;AAAA,gBACV,iBAAc;AAAA,gBACd,gBAAc,CAAC,CAAC;AAAA;AAAA,YAClB;AAAA,aACF;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACC,MAAK;AAAA,cACL,UAAU;AAAA,cACV,WAAW,GAAG,OAAO,MAAM,IAAI,aAAa,UAAU,EAAE;AAAA,cACxD,eAAY;AAAA,cAEX,oBAAU,kBAAkB;AAAA;AAAA,UAC/B;AAAA;AAAA;AAAA,IACF,GACF,GACF;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": ["import_auth", "auth", "styles"]
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -149,17 +149,33 @@ init_ternSecureClientProvider();
|
|
|
149
149
|
var import_react3 = __toESM(require("react"), 1);
|
|
150
150
|
var import_dynamic = __toESM(require("next/dynamic"), 1);
|
|
151
151
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
152
|
+
var LoadingProvider = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
153
|
+
"div",
|
|
154
|
+
{
|
|
155
|
+
"aria-label": "Loading authentication provider...",
|
|
156
|
+
role: "status",
|
|
157
|
+
style: { display: "none" }
|
|
158
|
+
}
|
|
159
|
+
);
|
|
152
160
|
var TernSecureClientProvider2 = (0, import_dynamic.default)(
|
|
153
161
|
() => Promise.resolve().then(() => (init_ternSecureClientProvider(), ternSecureClientProvider_exports)).then((mod) => mod.TernSecureClientProvider),
|
|
154
162
|
{
|
|
155
|
-
ssr: false
|
|
156
|
-
|
|
163
|
+
//ssr: false,
|
|
164
|
+
loading: LoadingProvider
|
|
165
|
+
// Return null or a loading indicator
|
|
157
166
|
}
|
|
158
167
|
);
|
|
159
168
|
function TernSecureProvider({ children }) {
|
|
169
|
+
const startTime = process.env.NODE_ENV === "development" ? performance.now() : 0;
|
|
160
170
|
const isRootLayout = import_react3.default.Children.toArray(children).some(
|
|
161
171
|
(child) => import_react3.default.isValidElement(child) && child.type === "html"
|
|
162
172
|
);
|
|
173
|
+
import_react3.default.useEffect(() => {
|
|
174
|
+
if (process.env.NODE_ENV === "development") {
|
|
175
|
+
const endTime = performance.now();
|
|
176
|
+
console.debug(`TernSecure provider mounted in ${endTime - startTime}ms`);
|
|
177
|
+
}
|
|
178
|
+
}, [startTime]);
|
|
163
179
|
if (isRootLayout) {
|
|
164
180
|
return import_react3.default.Children.map(children, (child) => {
|
|
165
181
|
if (import_react3.default.isValidElement(child) && child.type === "html") {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/app-router/client/providers/ternSecureContext.tsx", "../../src/app-router/client/providers/ternSecureClientProvider.tsx", "../../src/index.ts", "../../src/app-router/client/client-init.ts", "../../src/app-router/client/config.ts", "../../src/app-router/client/auth.ts", "../../src/app-router/client/index.ts", "../../src/app-router/server/providers/TernSecureServerProvider.tsx", "../../src/hooks/useAuth.ts", "../../src/components/sign-in.tsx", "../../src/utils/create-styles.ts"],
|
|
4
|
-
"sourcesContent": ["'use client'\r\n\r\nimport { createContext, useContext } from 'react'\r\n\r\n/**\r\n * Internal context type for TernSecure authentication\r\n * @internal\r\n */\r\ninterface TernSecureContextType {\r\n readonly _contextKey: symbol\r\n}\r\n\r\n/**\r\n * Internal symbol used for context validation\r\n * @internal\r\n */\r\nconst INTERNAL_CONTEXT_KEY = Symbol('TERN_SECURE_CONTEXT')\r\n\r\n/**\r\n * Context for TernSecure authentication\r\n * @internal\r\n */\r\nconst TernSecureContext = createContext<TernSecureContextType | null>(null)\r\n\r\n/**\r\n * Hook to verify that components are rendered within the TernSecure provider\r\n * @param hookName - Name of the hook being used (for better error messages)\r\n * @throws {Error} When used outside of TernSecureProvider\r\n * @internal\r\n */\r\nconst useInternalContext = (hookName?: string): TernSecureContextType => {\r\n const context = useContext(TernSecureContext)\r\n \r\n if (!context || context._contextKey !== INTERNAL_CONTEXT_KEY) {\r\n throw new Error(\r\n `${hookName || 'Hook'} must be used within TernSecureProvider. ` +\r\n 'Please wrap your component with TernSecureProvider.'\r\n )\r\n }\r\n \r\n return context\r\n}\r\n\r\nexport {\r\n type TernSecureContextType,\r\n TernSecureContext,\r\n useInternalContext,\r\n INTERNAL_CONTEXT_KEY\r\n}", "'use client'\r\n\r\nimport React from 'react'\r\nimport { INTERNAL_CONTEXT_KEY, TernSecureContext, TernSecureContextType } from './ternSecureContext'\r\n\r\n/**\r\n * Props for the TernSecureClientProvider component\r\n */\r\ninterface TernSecureClientProviderProps {\r\n /** React child elements to be wrapped by the provider */\r\n children: React.ReactNode\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure authentication\r\n * Must be used to wrap any components that use TernSecure hooks\r\n * \r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * return (\r\n * <TernSecureClientProvider>\r\n * <YourApp />\r\n * </TernSecureClientProvider>\r\n * )\r\n * }\r\n * ```\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProviderProps): JSX.Element {\r\n // Memoize the context value to prevent unnecessary re-renders\r\n const contextValue = React.useMemo<TernSecureContextType>(\r\n () => ({ _contextKey: INTERNAL_CONTEXT_KEY }),\r\n []\r\n )\r\n\r\n return (\r\n <TernSecureContext.Provider value={contextValue}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\n// Add display name for better debugging\r\nTernSecureClientProvider.displayName = 'TernSecureClientProvider'", "export { TernSecureAuth, TernSecureFirestore, TernSecureStorage, signInWithEmail, loadFireConfig, validateConfig, TernSecureContext, useInternalContext, TernSecureClientProvider } from './app-router/client'\r\nexport { TernSecureProvider } from './app-router/server'\r\nexport { useAuth } from './hooks/useAuth' \r\nexport { SignIn } from './components/sign-in'", "import { getApps, 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 { loadFireConfig, validateConfig } from './config';\r\n\r\n// Initialize immediately\r\nconst app = (() => {\r\n const config = validateConfig(loadFireConfig());\r\n return getApps().length ? getApps()[0] : initializeApp(config);\r\n})();\r\n\r\nconst auth = getAuth(app);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(app);\r\nconst storage = getStorage(app);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;", "import { TernSecureConfig } from \"../../types\";\r\n\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY as string,\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN as string,\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID as string,\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET as string,\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID as string,\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID as string,\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID as string,\r\n});\r\n\r\nexport const validateConfig = (config: TernSecureConfig): TernSecureConfig => {\r\n Object.entries(config).forEach(([key, value]) => {\r\n if (!value) {\r\n throw new Error(`Missing environment variable: NEXT_PUBLIC_FIREBASE_${key.toUpperCase()}`);\r\n }\r\n });\r\n return config;\r\n};", "import { TernSecureAuth } from './index'\r\nimport { signInWithEmailAndPassword, type UserCredential } from 'firebase/auth'\r\n\r\nexport interface SignInCredentials {\r\n email: string\r\n password: string\r\n}\r\n\r\nexport async function signInWithEmail({ \r\n email, \r\n password \r\n}: SignInCredentials): Promise<UserCredential> {\r\n const auth = TernSecureAuth()\r\n return signInWithEmailAndPassword(auth, email, password)\r\n} ", "'use client'\r\nexport { \r\n TernSecureAuth,\r\n TernSecureFirestore,\r\n TernSecureStorage \r\n } from './client-init';\r\n\r\n export type { SignInCredentials } from './auth'\r\n\r\n export { signInWithEmail} from './auth'\r\n export { loadFireConfig, validateConfig } from './config';\r\n export { TernSecureContext, useInternalContext } from './providers/ternSecureContext';\r\n export { TernSecureClientProvider } from './providers/ternSecureClientProvider'", "import React, { ReactNode } from 'react';\r\nimport dynamic from 'next/dynamic'\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\n// Dynamically import the client provider with no SSR\r\nconst TernSecureClientProvider = dynamic(\r\n () => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n ssr: false\r\n //loading: () => null // Return null or a loading indicator\r\n }\r\n)\r\n\r\nexport function TernSecureProvider({ children }: TernSecureProviderProps) {\r\n // Check if the children contain html/body tags\r\n const isRootLayout = React.Children.toArray(children).some(\r\n child => React.isValidElement(child) && child.type === 'html'\r\n );\r\n\r\n if (isRootLayout) {\r\n // If this is the root layout, inject our provider after the body tag\r\n return React.Children.map(children, child => {\r\n if (React.isValidElement(child) && child.type === 'html') {\r\n return React.cloneElement(child, {}, \r\n React.Children.map(child.props.children, bodyChild => {\r\n if (React.isValidElement(bodyChild) && bodyChild.type === 'body') {\r\n // Type assertion to access props safely\r\n const bodyProps = bodyChild.props as { children: ReactNode };\r\n return React.cloneElement(bodyChild, {}, \r\n <TernSecureClientProvider>\r\n {bodyProps.children}\r\n </TernSecureClientProvider>\r\n );\r\n }\r\n return bodyChild;\r\n })\r\n );\r\n }\r\n return child;\r\n });\r\n }\r\n\r\n // For non-root layouts, wrap normally\r\n return <TernSecureClientProvider>{children}</TernSecureClientProvider>;\r\n}", "'use client'\r\n\r\nimport { useEffect, useState, useMemo } from 'react'\r\nimport { onAuthStateChanged } from 'firebase/auth'\r\nimport { TernSecureAuth } from '../app-router/client'\r\nimport { useInternalContext } from '../app-router/client'\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\r\n 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 }, [auth])\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}", "import * as React from 'react'\r\nimport { useState } from 'react'\r\nimport { signInWithEmail } from '../app-router/client'\r\nimport { styles } from '../utils/create-styles'\r\n\r\nexport interface SignInProps {\r\n onSuccess?: () => void\r\n onError?: (error: Error) => void\r\n redirectUrl?: string\r\n className?: string\r\n style?: React.CSSProperties\r\n customStyles?: {\r\n container?: string\r\n header?: string\r\n title?: string\r\n formWrapper?: string\r\n formContainer?: string\r\n form?: string\r\n input?: string\r\n button?: string\r\n errorText?: string\r\n label?: string\r\n }\r\n}\r\n\r\nexport function SignIn({ \r\n onSuccess, \r\n onError, \r\n redirectUrl,\r\n className = '',\r\n style,\r\n customStyles = {}\r\n}: SignInProps) {\r\n const [email, setEmail] = useState('')\r\n const [password, setPassword] = useState('')\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState('')\r\n\r\n const handleSubmit = async (e: React.FormEvent) => {\r\n e.preventDefault()\r\n setLoading(true)\r\n setError('')\r\n\r\n try {\r\n await signInWithEmail({ email, password })\r\n onSuccess?.()\r\n \r\n if (redirectUrl) {\r\n window.location.href = redirectUrl\r\n }\r\n } catch (err) {\r\n const errorMessage = err instanceof Error ? err.message : 'Failed to sign in'\r\n setError(errorMessage)\r\n onError?.(err instanceof Error ? err : new Error('Failed to sign in'))\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n return (\r\n <div className={`${styles.container} ${customStyles.container || ''}`} style={style}>\r\n <div className={`${styles.header} ${customStyles.header || ''}`}>\r\n <h2 className={`${styles.title} ${customStyles.title || ''}`}>\r\n Sign in to your account\r\n </h2>\r\n </div>\r\n \r\n <div className={`${styles.formWrapper} ${customStyles.formWrapper || ''}`}>\r\n <div className={`${styles.formContainer} ${customStyles.formContainer || ''}`}>\r\n <form \r\n onSubmit={handleSubmit} \r\n className={`${styles.form} ${customStyles.form || ''} ${className}`}\r\n role=\"form\"\r\n aria-label=\"Sign in form\"\r\n >\r\n {error && (\r\n <div \r\n className={`${styles.error} ${customStyles.errorText || ''}`}\r\n role=\"alert\"\r\n aria-live=\"polite\"\r\n >\r\n {error}\r\n </div>\r\n )}\r\n <div>\r\n <label htmlFor=\"email\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Email\r\n </label>\r\n <input\r\n id=\"email\"\r\n type=\"email\"\r\n value={email}\r\n onChange={(e) => setEmail(e.target.value)}\r\n placeholder=\"Enter your email\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <div>\r\n <label htmlFor=\"password\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Password\r\n </label>\r\n <input\r\n id=\"password\"\r\n type=\"password\"\r\n value={password}\r\n onChange={(e) => setPassword(e.target.value)}\r\n placeholder=\"Enter your password\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <button \r\n type=\"submit\" \r\n disabled={loading}\r\n className={`${styles.button} ${customStyles.button || ''}`}\r\n data-testid=\"sign-in-submit\"\r\n >\r\n {loading ? 'Signing in...' : 'Sign in'}\r\n </button>\r\n </form>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\n", "'use client'\r\n\r\nconst PREFIX = 'tern'\r\n\r\n// Singleton to track style injection\r\nconst styleInjection = {\r\n isInjected: false,\r\n styleElement: null as HTMLStyleElement | null\r\n}\r\n\r\nexport const defaultClassNames = {\r\n container: `${PREFIX}-container`,\r\n header: `${PREFIX}-header`,\r\n title: `${PREFIX}-title`,\r\n formWrapper: `${PREFIX}-formWrapper`,\r\n formContainer: `${PREFIX}-formContainer`,\r\n form: `${PREFIX}-form`,\r\n label: `${PREFIX}-label`,\r\n input: `${PREFIX}-input`,\r\n button: `${PREFIX}-button`,\r\n error: `${PREFIX}-error`\r\n} as const\r\n\r\n// Create styles once and cache them\r\nfunction createStyleSheet(styles: Record<string, React.CSSProperties>) {\r\n if (typeof window === 'undefined') return defaultClassNames\r\n\r\n // Return early if styles are already injected\r\n if (styleInjection.isInjected) {\r\n return defaultClassNames\r\n }\r\n\r\n // Find existing style element or create new one\r\n let styleElement = document.querySelector<HTMLStyleElement>('[data-tern-secure]')\r\n \r\n if (!styleElement) {\r\n styleElement = document.createElement('style')\r\n styleElement.setAttribute('data-tern-secure', '')\r\n document.head.appendChild(styleElement)\r\n styleInjection.styleElement = styleElement\r\n }\r\n\r\n // Create CSS rules\r\n const cssRules = Object.entries(styles).map(([key, rules]) => {\r\n const className = defaultClassNames[key as keyof typeof defaultClassNames]\r\n const cssProperties = Object.entries(rules).map(([prop, value]) => {\r\n const cssProperty = prop.replace(/([A-Z])/g, '-$1').toLowerCase()\r\n return `${cssProperty}: ${value};`\r\n }).join(' ')\r\n\r\n return `.${className} { ${cssProperties} }`\r\n }).join('\\n')\r\n\r\n // Insert styles only once\r\n styleElement.textContent = cssRules\r\n styleInjection.isInjected = true\r\n\r\n return defaultClassNames\r\n}\r\n\r\n// Style configuration\r\nexport const styleConfig = {\r\n container: {\r\n display: 'flex',\r\n minHeight: '100%',\r\n flex: '1',\r\n flexDirection: 'column',\r\n justifyContent: 'center',\r\n padding: '3rem 1.5rem'\r\n },\r\n header: {\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '28rem'\r\n },\r\n title: {\r\n marginTop: '1.5rem',\r\n textAlign: 'center',\r\n fontSize: '1.875rem',\r\n fontWeight: '700',\r\n lineHeight: '2.25rem',\r\n letterSpacing: '-0.025em',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n formWrapper: {\r\n marginTop: '2.5rem',\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '30rem'\r\n },\r\n formContainer: {\r\n padding: '3rem 1.5rem',\r\n boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)',\r\n borderRadius: '0.5rem',\r\n backgroundColor: 'var(--tern-background, white)'\r\n },\r\n form: {\r\n display: 'flex',\r\n flexDirection: 'column',\r\n gap: '1rem'\r\n },\r\n label: {\r\n display: 'block',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'var(--tern-text-secondary, #374151)'\r\n },\r\n input: {\r\n marginTop: '0.25rem',\r\n display: 'block',\r\n width: '100%',\r\n padding: '0.5rem 0.75rem',\r\n borderRadius: '0.375rem',\r\n border: '1px solid var(--tern-border, #D1D5DB)',\r\n backgroundColor: 'var(--tern-input-background, white)',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n button: {\r\n display: 'flex',\r\n width: '100%',\r\n justifyContent: 'center',\r\n padding: '0.5rem 1rem',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'white',\r\n backgroundColor: 'var(--tern-primary, #2563EB)',\r\n border: 'none',\r\n borderRadius: '0.375rem',\r\n cursor: 'pointer'\r\n },\r\n error: {\r\n color: 'var(--tern-error, #DC2626)',\r\n fontSize: '0.875rem'\r\n }\r\n} as const\r\n\r\n// Export pre-created styles\r\nexport const styles = createStyleSheet(styleConfig)\r\n\r\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAEA,cAcM,sBAMA,mBAQA;AA9BN;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAc1C,IAAM,uBAAuB,OAAO,qBAAqB;AAMzD,IAAM,wBAAoB,4BAA4C,IAAI;AAQ1E,IAAM,qBAAqB,CAAC,aAA6C;AACvE,YAAM,cAAU,yBAAW,iBAAiB;AAE5C,UAAI,CAAC,WAAW,QAAQ,gBAAgB,sBAAsB;AAC5D,cAAM,IAAI;AAAA,UACR,GAAG,YAAY,MAAM;AAAA,QAEvB;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA;AAAA;;;ACzCA;AAAA;AAAA;AAAA;AA4BO,SAAS,yBAAyB,EAAE,SAAS,GAA+C;AAEjG,QAAM,eAAe,cAAAA,QAAM;AAAA,IACzB,OAAO,EAAE,aAAa,qBAAqB;AAAA,IAC3C,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,kBAAkB,UAAlB,EAA2B,OAAO,cAChC,UACH;AAEJ;AAxCA,IAEAC,eAkCI;AApCJ;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAAkB;AAClB;AAiCI;AAOJ,6BAAyB,cAAc;AAAA;AAAA;;;AC3CvC;AAAA;AAAA;AAAA;AAAA;AAAA;A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useContext } from 'react'\r\n\r\n/**\r\n * Internal context type for TernSecure authentication\r\n * @internal\r\n */\r\ninterface TernSecureContextType {\r\n readonly _contextKey: symbol\r\n}\r\n\r\n/**\r\n * Internal symbol used for context validation\r\n * @internal\r\n */\r\nconst INTERNAL_CONTEXT_KEY = Symbol('TERN_SECURE_CONTEXT')\r\n\r\n/**\r\n * Context for TernSecure authentication\r\n * @internal\r\n */\r\nconst TernSecureContext = createContext<TernSecureContextType | null>(null)\r\n\r\n/**\r\n * Hook to verify that components are rendered within the TernSecure provider\r\n * @param hookName - Name of the hook being used (for better error messages)\r\n * @throws {Error} When used outside of TernSecureProvider\r\n * @internal\r\n */\r\nconst useInternalContext = (hookName?: string): TernSecureContextType => {\r\n const context = useContext(TernSecureContext)\r\n \r\n if (!context || context._contextKey !== INTERNAL_CONTEXT_KEY) {\r\n throw new Error(\r\n `${hookName || 'Hook'} must be used within TernSecureProvider. ` +\r\n 'Please wrap your component with TernSecureProvider.'\r\n )\r\n }\r\n \r\n return context\r\n}\r\n\r\nexport {\r\n type TernSecureContextType,\r\n TernSecureContext,\r\n useInternalContext,\r\n INTERNAL_CONTEXT_KEY\r\n}", "'use client'\r\n\r\nimport React from 'react'\r\nimport { INTERNAL_CONTEXT_KEY, TernSecureContext, TernSecureContextType } from './ternSecureContext'\r\n\r\n/**\r\n * Props for the TernSecureClientProvider component\r\n */\r\ninterface TernSecureClientProviderProps {\r\n /** React child elements to be wrapped by the provider */\r\n children: React.ReactNode\r\n}\r\n\r\n/**\r\n * Provider component for TernSecure authentication\r\n * Must be used to wrap any components that use TernSecure hooks\r\n * \r\n * @example\r\n * ```tsx\r\n * function App() {\r\n * return (\r\n * <TernSecureClientProvider>\r\n * <YourApp />\r\n * </TernSecureClientProvider>\r\n * )\r\n * }\r\n * ```\r\n */\r\nexport function TernSecureClientProvider({ children }: TernSecureClientProviderProps): JSX.Element {\r\n // Memoize the context value to prevent unnecessary re-renders\r\n const contextValue = React.useMemo<TernSecureContextType>(\r\n () => ({ _contextKey: INTERNAL_CONTEXT_KEY }),\r\n []\r\n )\r\n\r\n return (\r\n <TernSecureContext.Provider value={contextValue}>\r\n {children}\r\n </TernSecureContext.Provider>\r\n )\r\n}\r\n\r\n// Add display name for better debugging\r\nTernSecureClientProvider.displayName = 'TernSecureClientProvider'", "export { TernSecureAuth, TernSecureFirestore, TernSecureStorage, signInWithEmail, loadFireConfig, validateConfig, TernSecureContext, useInternalContext, TernSecureClientProvider } from './app-router/client'\r\nexport { TernSecureProvider } from './app-router/server'\r\nexport { useAuth } from './hooks/useAuth' \r\nexport { SignIn } from './components/sign-in'", "import { getApps, 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 { loadFireConfig, validateConfig } from './config';\r\n\r\n// Initialize immediately\r\nconst app = (() => {\r\n const config = validateConfig(loadFireConfig());\r\n return getApps().length ? getApps()[0] : initializeApp(config);\r\n})();\r\n\r\nconst auth = getAuth(app);\r\nsetPersistence(auth, browserSessionPersistence); //to change later user should be able to choose persistance\r\nconst firestore = getFirestore(app);\r\nconst storage = getStorage(app);\r\n\r\nexport const TernSecureAuth = () => auth;\r\nexport const TernSecureFirestore = () => firestore;\r\nexport const TernSecureStorage = () => storage;", "import { TernSecureConfig } from \"../../types\";\r\n\r\nexport const loadFireConfig = (): TernSecureConfig => ({\r\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY as string,\r\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN as string,\r\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID as string,\r\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET as string,\r\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID as string,\r\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID as string,\r\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID as string,\r\n});\r\n\r\nexport const validateConfig = (config: TernSecureConfig): TernSecureConfig => {\r\n Object.entries(config).forEach(([key, value]) => {\r\n if (!value) {\r\n throw new Error(`Missing environment variable: NEXT_PUBLIC_FIREBASE_${key.toUpperCase()}`);\r\n }\r\n });\r\n return config;\r\n};", "import { TernSecureAuth } from './index'\r\nimport { signInWithEmailAndPassword, type UserCredential } from 'firebase/auth'\r\n\r\nexport interface SignInCredentials {\r\n email: string\r\n password: string\r\n}\r\n\r\nexport async function signInWithEmail({ \r\n email, \r\n password \r\n}: SignInCredentials): Promise<UserCredential> {\r\n const auth = TernSecureAuth()\r\n return signInWithEmailAndPassword(auth, email, password)\r\n} ", "'use client'\r\nexport { \r\n TernSecureAuth,\r\n TernSecureFirestore,\r\n TernSecureStorage \r\n } from './client-init';\r\n\r\n export type { SignInCredentials } from './auth'\r\n\r\n export { signInWithEmail} from './auth'\r\n export { loadFireConfig, validateConfig } from './config';\r\n export { TernSecureContext, useInternalContext } from './providers/ternSecureContext';\r\n export { TernSecureClientProvider } from './providers/ternSecureClientProvider'", "import React, { ReactNode } from 'react';\r\nimport dynamic from 'next/dynamic'\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\n// Lightweight loading component\r\nconst LoadingProvider = () => (\r\n <div \r\n aria-label=\"Loading authentication provider...\" \r\n role=\"status\"\r\n style={{ display: 'none' }}\r\n />\r\n)\r\n\r\n// Dynamically import the client provider with no SSR\r\nconst TernSecureClientProvider = dynamic(\r\n () => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n //ssr: false,\r\n loading: LoadingProvider // Return null or a loading indicator\r\n }\r\n)\r\n\r\nexport function TernSecureProvider({ children }: TernSecureProviderProps) {\r\n const startTime = process.env.NODE_ENV === 'development' ? performance.now() : 0\r\n\r\n // Check if the children contain html/body tags\r\n const isRootLayout = React.Children.toArray(children).some(\r\n child => React.isValidElement(child) && child.type === 'html'\r\n );\r\n\r\n // Log performance in development\r\n React.useEffect(() => {\r\n if (process.env.NODE_ENV === 'development') {\r\n const endTime = performance.now()\r\n console.debug(`TernSecure provider mounted in ${endTime - startTime}ms`)\r\n }\r\n }, [startTime])\r\n\r\n if (isRootLayout) {\r\n // If this is the root layout, inject our provider after the body tag\r\n return React.Children.map(children, child => {\r\n if (React.isValidElement(child) && child.type === 'html') {\r\n return React.cloneElement(child, {}, \r\n React.Children.map(child.props.children, bodyChild => {\r\n if (React.isValidElement(bodyChild) && bodyChild.type === 'body') {\r\n // Type assertion to access props safely\r\n const bodyProps = bodyChild.props as { children: ReactNode };\r\n return React.cloneElement(bodyChild, {}, \r\n <TernSecureClientProvider>\r\n {bodyProps.children}\r\n </TernSecureClientProvider>\r\n );\r\n }\r\n return bodyChild;\r\n })\r\n );\r\n }\r\n return child;\r\n });\r\n }\r\n\r\n // For non-root layouts, wrap normally\r\n return <TernSecureClientProvider>{children}</TernSecureClientProvider>;\r\n}", "'use client'\r\n\r\nimport { useEffect, useState, useMemo } from 'react'\r\nimport { onAuthStateChanged } from 'firebase/auth'\r\nimport { TernSecureAuth } from '../app-router/client'\r\nimport { useInternalContext } from '../app-router/client'\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\r\n 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 }, [auth])\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}", "import * as React from 'react'\r\nimport { useState } from 'react'\r\nimport { signInWithEmail } from '../app-router/client'\r\nimport { styles } from '../utils/create-styles'\r\n\r\nexport interface SignInProps {\r\n onSuccess?: () => void\r\n onError?: (error: Error) => void\r\n redirectUrl?: string\r\n className?: string\r\n style?: React.CSSProperties\r\n customStyles?: {\r\n container?: string\r\n header?: string\r\n title?: string\r\n formWrapper?: string\r\n formContainer?: string\r\n form?: string\r\n input?: string\r\n button?: string\r\n errorText?: string\r\n label?: string\r\n }\r\n}\r\n\r\nexport function SignIn({ \r\n onSuccess, \r\n onError, \r\n redirectUrl,\r\n className = '',\r\n style,\r\n customStyles = {}\r\n}: SignInProps) {\r\n const [email, setEmail] = useState('')\r\n const [password, setPassword] = useState('')\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState('')\r\n\r\n const handleSubmit = async (e: React.FormEvent) => {\r\n e.preventDefault()\r\n setLoading(true)\r\n setError('')\r\n\r\n try {\r\n await signInWithEmail({ email, password })\r\n onSuccess?.()\r\n \r\n if (redirectUrl) {\r\n window.location.href = redirectUrl\r\n }\r\n } catch (err) {\r\n const errorMessage = err instanceof Error ? err.message : 'Failed to sign in'\r\n setError(errorMessage)\r\n onError?.(err instanceof Error ? err : new Error('Failed to sign in'))\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n return (\r\n <div className={`${styles.container} ${customStyles.container || ''}`} style={style}>\r\n <div className={`${styles.header} ${customStyles.header || ''}`}>\r\n <h2 className={`${styles.title} ${customStyles.title || ''}`}>\r\n Sign in to your account\r\n </h2>\r\n </div>\r\n \r\n <div className={`${styles.formWrapper} ${customStyles.formWrapper || ''}`}>\r\n <div className={`${styles.formContainer} ${customStyles.formContainer || ''}`}>\r\n <form \r\n onSubmit={handleSubmit} \r\n className={`${styles.form} ${customStyles.form || ''} ${className}`}\r\n role=\"form\"\r\n aria-label=\"Sign in form\"\r\n >\r\n {error && (\r\n <div \r\n className={`${styles.error} ${customStyles.errorText || ''}`}\r\n role=\"alert\"\r\n aria-live=\"polite\"\r\n >\r\n {error}\r\n </div>\r\n )}\r\n <div>\r\n <label htmlFor=\"email\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Email\r\n </label>\r\n <input\r\n id=\"email\"\r\n type=\"email\"\r\n value={email}\r\n onChange={(e) => setEmail(e.target.value)}\r\n placeholder=\"Enter your email\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <div>\r\n <label htmlFor=\"password\" className={`${styles.label} ${customStyles.label || ''}`}>\r\n Password\r\n </label>\r\n <input\r\n id=\"password\"\r\n type=\"password\"\r\n value={password}\r\n onChange={(e) => setPassword(e.target.value)}\r\n placeholder=\"Enter your password\"\r\n required\r\n className={`${styles.input} ${customStyles.input || ''}`}\r\n disabled={loading}\r\n aria-required=\"true\"\r\n aria-invalid={!!error}\r\n />\r\n </div>\r\n <button \r\n type=\"submit\" \r\n disabled={loading}\r\n className={`${styles.button} ${customStyles.button || ''}`}\r\n data-testid=\"sign-in-submit\"\r\n >\r\n {loading ? 'Signing in...' : 'Sign in'}\r\n </button>\r\n </form>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\n", "'use client'\r\n\r\nconst PREFIX = 'tern'\r\n\r\n// Singleton to track style injection\r\nconst styleInjection = {\r\n isInjected: false,\r\n styleElement: null as HTMLStyleElement | null\r\n}\r\n\r\nexport const defaultClassNames = {\r\n container: `${PREFIX}-container`,\r\n header: `${PREFIX}-header`,\r\n title: `${PREFIX}-title`,\r\n formWrapper: `${PREFIX}-formWrapper`,\r\n formContainer: `${PREFIX}-formContainer`,\r\n form: `${PREFIX}-form`,\r\n label: `${PREFIX}-label`,\r\n input: `${PREFIX}-input`,\r\n button: `${PREFIX}-button`,\r\n error: `${PREFIX}-error`\r\n} as const\r\n\r\n// Create styles once and cache them\r\nfunction createStyleSheet(styles: Record<string, React.CSSProperties>) {\r\n if (typeof window === 'undefined') return defaultClassNames\r\n\r\n // Return early if styles are already injected\r\n if (styleInjection.isInjected) {\r\n return defaultClassNames\r\n }\r\n\r\n // Find existing style element or create new one\r\n let styleElement = document.querySelector<HTMLStyleElement>('[data-tern-secure]')\r\n \r\n if (!styleElement) {\r\n styleElement = document.createElement('style')\r\n styleElement.setAttribute('data-tern-secure', '')\r\n document.head.appendChild(styleElement)\r\n styleInjection.styleElement = styleElement\r\n }\r\n\r\n // Create CSS rules\r\n const cssRules = Object.entries(styles).map(([key, rules]) => {\r\n const className = defaultClassNames[key as keyof typeof defaultClassNames]\r\n const cssProperties = Object.entries(rules).map(([prop, value]) => {\r\n const cssProperty = prop.replace(/([A-Z])/g, '-$1').toLowerCase()\r\n return `${cssProperty}: ${value};`\r\n }).join(' ')\r\n\r\n return `.${className} { ${cssProperties} }`\r\n }).join('\\n')\r\n\r\n // Insert styles only once\r\n styleElement.textContent = cssRules\r\n styleInjection.isInjected = true\r\n\r\n return defaultClassNames\r\n}\r\n\r\n// Style configuration\r\nexport const styleConfig = {\r\n container: {\r\n display: 'flex',\r\n minHeight: '100%',\r\n flex: '1',\r\n flexDirection: 'column',\r\n justifyContent: 'center',\r\n padding: '3rem 1.5rem'\r\n },\r\n header: {\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '28rem'\r\n },\r\n title: {\r\n marginTop: '1.5rem',\r\n textAlign: 'center',\r\n fontSize: '1.875rem',\r\n fontWeight: '700',\r\n lineHeight: '2.25rem',\r\n letterSpacing: '-0.025em',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n formWrapper: {\r\n marginTop: '2.5rem',\r\n margin: '0 auto',\r\n width: '100%',\r\n maxWidth: '30rem'\r\n },\r\n formContainer: {\r\n padding: '3rem 1.5rem',\r\n boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)',\r\n borderRadius: '0.5rem',\r\n backgroundColor: 'var(--tern-background, white)'\r\n },\r\n form: {\r\n display: 'flex',\r\n flexDirection: 'column',\r\n gap: '1rem'\r\n },\r\n label: {\r\n display: 'block',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'var(--tern-text-secondary, #374151)'\r\n },\r\n input: {\r\n marginTop: '0.25rem',\r\n display: 'block',\r\n width: '100%',\r\n padding: '0.5rem 0.75rem',\r\n borderRadius: '0.375rem',\r\n border: '1px solid var(--tern-border, #D1D5DB)',\r\n backgroundColor: 'var(--tern-input-background, white)',\r\n color: 'var(--tern-text-primary, #111827)'\r\n },\r\n button: {\r\n display: 'flex',\r\n width: '100%',\r\n justifyContent: 'center',\r\n padding: '0.5rem 1rem',\r\n fontSize: '0.875rem',\r\n fontWeight: '500',\r\n color: 'white',\r\n backgroundColor: 'var(--tern-primary, #2563EB)',\r\n border: 'none',\r\n borderRadius: '0.375rem',\r\n cursor: 'pointer'\r\n },\r\n error: {\r\n color: 'var(--tern-error, #DC2626)',\r\n fontSize: '0.875rem'\r\n }\r\n} as const\r\n\r\n// Export pre-created styles\r\nexport const styles = createStyleSheet(styleConfig)\r\n\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAEA,cAcM,sBAMA,mBAQA;AA9BN;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAc1C,IAAM,uBAAuB,OAAO,qBAAqB;AAMzD,IAAM,wBAAoB,4BAA4C,IAAI;AAQ1E,IAAM,qBAAqB,CAAC,aAA6C;AACvE,YAAM,cAAU,yBAAW,iBAAiB;AAE5C,UAAI,CAAC,WAAW,QAAQ,gBAAgB,sBAAsB;AAC5D,cAAM,IAAI;AAAA,UACR,GAAG,YAAY,MAAM;AAAA,QAEvB;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA;AAAA;;;ACzCA;AAAA;AAAA;AAAA;A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BAAkB;AAAA;AAAA,UAC/B;AAAA;AAAA;AAAA,IACF,GACF,GACF;AAAA,KACF;AAEJ;",
|
|
6
6
|
"names": ["React", "import_react", "import_auth", "auth", "import_react", "import_jsx_runtime", "TernSecureClientProvider", "dynamic", "React", "import_react", "import_auth", "auth", "import_react", "styles", "import_jsx_runtime"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TernSecureServerProvider.d.ts","sourceRoot":"","sources":["../../../../../src/app-router/server/providers/TernSecureServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzC,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,SAAS,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"TernSecureServerProvider.d.ts","sourceRoot":"","sources":["../../../../../src/app-router/server/providers/TernSecureServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzC,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAoBD,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,uBAAuB,qLAyCvE"}
|
|
@@ -2,17 +2,33 @@
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import dynamic from "next/dynamic";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var LoadingProvider = () => /* @__PURE__ */ jsx(
|
|
6
|
+
"div",
|
|
7
|
+
{
|
|
8
|
+
"aria-label": "Loading authentication provider...",
|
|
9
|
+
role: "status",
|
|
10
|
+
style: { display: "none" }
|
|
11
|
+
}
|
|
12
|
+
);
|
|
5
13
|
var TernSecureClientProvider = dynamic(
|
|
6
14
|
() => import("./ternSecureClientProvider-AFCR7MAX.js").then((mod) => mod.TernSecureClientProvider),
|
|
7
15
|
{
|
|
8
|
-
ssr: false
|
|
9
|
-
|
|
16
|
+
//ssr: false,
|
|
17
|
+
loading: LoadingProvider
|
|
18
|
+
// Return null or a loading indicator
|
|
10
19
|
}
|
|
11
20
|
);
|
|
12
21
|
function TernSecureProvider({ children }) {
|
|
22
|
+
const startTime = process.env.NODE_ENV === "development" ? performance.now() : 0;
|
|
13
23
|
const isRootLayout = React.Children.toArray(children).some(
|
|
14
24
|
(child) => React.isValidElement(child) && child.type === "html"
|
|
15
25
|
);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (process.env.NODE_ENV === "development") {
|
|
28
|
+
const endTime = performance.now();
|
|
29
|
+
console.debug(`TernSecure provider mounted in ${endTime - startTime}ms`);
|
|
30
|
+
}
|
|
31
|
+
}, [startTime]);
|
|
16
32
|
if (isRootLayout) {
|
|
17
33
|
return React.Children.map(children, (child) => {
|
|
18
34
|
if (React.isValidElement(child) && child.type === "html") {
|
|
@@ -41,4 +57,4 @@ function TernSecureProvider({ children }) {
|
|
|
41
57
|
export {
|
|
42
58
|
TernSecureProvider
|
|
43
59
|
};
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-XXCJHKRH.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/app-router/server/providers/TernSecureServerProvider.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { ReactNode } from 'react';\r\nimport dynamic from 'next/dynamic'\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\n// Lightweight loading component\r\nconst LoadingProvider = () => (\r\n <div \r\n aria-label=\"Loading authentication provider...\" \r\n role=\"status\"\r\n style={{ display: 'none' }}\r\n />\r\n)\r\n\r\n// Dynamically import the client provider with no SSR\r\nconst TernSecureClientProvider = dynamic(\r\n () => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n //ssr: false,\r\n loading: LoadingProvider // Return null or a loading indicator\r\n }\r\n)\r\n\r\nexport function TernSecureProvider({ children }: TernSecureProviderProps) {\r\n const startTime = process.env.NODE_ENV === 'development' ? performance.now() : 0\r\n\r\n // Check if the children contain html/body tags\r\n const isRootLayout = React.Children.toArray(children).some(\r\n child => React.isValidElement(child) && child.type === 'html'\r\n );\r\n\r\n // Log performance in development\r\n React.useEffect(() => {\r\n if (process.env.NODE_ENV === 'development') {\r\n const endTime = performance.now()\r\n console.debug(`TernSecure provider mounted in ${endTime - startTime}ms`)\r\n }\r\n }, [startTime])\r\n\r\n if (isRootLayout) {\r\n // If this is the root layout, inject our provider after the body tag\r\n return React.Children.map(children, child => {\r\n if (React.isValidElement(child) && child.type === 'html') {\r\n return React.cloneElement(child, {}, \r\n React.Children.map(child.props.children, bodyChild => {\r\n if (React.isValidElement(bodyChild) && bodyChild.type === 'body') {\r\n // Type assertion to access props safely\r\n const bodyProps = bodyChild.props as { children: ReactNode };\r\n return React.cloneElement(bodyChild, {}, \r\n <TernSecureClientProvider>\r\n {bodyProps.children}\r\n </TernSecureClientProvider>\r\n );\r\n }\r\n return bodyChild;\r\n })\r\n );\r\n }\r\n return child;\r\n });\r\n }\r\n\r\n // For non-root layouts, wrap normally\r\n return <TernSecureClientProvider>{children}</TernSecureClientProvider>;\r\n}"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,WAA0B;AACjC,OAAO,aAAa;AAQlB;AADF,IAAM,kBAAkB,MACtB;AAAA,EAAC;AAAA;AAAA,IACC,cAAW;AAAA,IACX,MAAK;AAAA,IACL,OAAO,EAAE,SAAS,OAAO;AAAA;AAC3B;AAIF,IAAM,2BAA2B;AAAA,EAC/B,MAAM,OAAO,wCAAiD,EAAE,KAAK,SAAO,IAAI,wBAAwB;AAAA,EACxG;AAAA;AAAA,IAEE,SAAS;AAAA;AAAA,EACX;AACF;AAEO,SAAS,mBAAmB,EAAE,SAAS,GAA4B;AACxE,QAAM,YAAY,QAAQ,IAAI,aAAa,gBAAgB,YAAY,IAAI,IAAI;AAG/E,QAAM,eAAe,MAAM,SAAS,QAAQ,QAAQ,EAAE;AAAA,IACpD,WAAS,MAAM,eAAe,KAAK,KAAK,MAAM,SAAS;AAAA,EACzD;AAGE,QAAM,UAAU,MAAM;AACpB,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,YAAM,UAAU,YAAY,IAAI;AAChC,cAAQ,MAAM,kCAAkC,UAAU,SAAS,IAAI;AAAA,IACzE;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEhB,MAAI,cAAc;AAEhB,WAAO,MAAM,SAAS,IAAI,UAAU,WAAS;AAC3C,UAAI,MAAM,eAAe,KAAK,KAAK,MAAM,SAAS,QAAQ;AACxD,eAAO,MAAM;AAAA,UAAa;AAAA,UAAO,CAAC;AAAA,UAChC,MAAM,SAAS,IAAI,MAAM,MAAM,UAAU,eAAa;AACpD,gBAAI,MAAM,eAAe,SAAS,KAAK,UAAU,SAAS,QAAQ;AAEhE,oBAAM,YAAY,UAAU;AAC5B,qBAAO,MAAM;AAAA,gBAAa;AAAA,gBAAW,CAAC;AAAA,gBACpC,oBAAC,4BACE,oBAAU,UACb;AAAA,cACF;AAAA,YACF;AACA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAGA,SAAO,oBAAC,4BAA0B,UAAS;AAC7C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tern-secure/nextjs",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.39",
|
|
4
4
|
"packageManager": "npm@10.9.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"files": [
|
|
78
78
|
"dist"
|
|
79
79
|
],
|
|
80
|
+
"sideEffects": false,
|
|
80
81
|
"peerDependencies": {
|
|
81
82
|
"firebase": "^10.0.0",
|
|
82
83
|
"next": "^13.0.0 || ^14.0.0 || ^15.0.0",
|
|
@@ -115,5 +116,8 @@
|
|
|
115
116
|
"import": "./dist/esm/components/index.js",
|
|
116
117
|
"require": "./dist/cjs/components/index.js"
|
|
117
118
|
}
|
|
119
|
+
},
|
|
120
|
+
"engines": {
|
|
121
|
+
"node": ">=18.17.0"
|
|
118
122
|
}
|
|
119
123
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/app-router/server/providers/TernSecureServerProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { ReactNode } from 'react';\r\nimport dynamic from 'next/dynamic'\r\n\r\ninterface TernSecureProviderProps {\r\n children: ReactNode;\r\n}\r\n\r\n// Dynamically import the client provider with no SSR\r\nconst TernSecureClientProvider = dynamic(\r\n () => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider),\r\n { \r\n ssr: false\r\n //loading: () => null // Return null or a loading indicator\r\n }\r\n)\r\n\r\nexport function TernSecureProvider({ children }: TernSecureProviderProps) {\r\n // Check if the children contain html/body tags\r\n const isRootLayout = React.Children.toArray(children).some(\r\n child => React.isValidElement(child) && child.type === 'html'\r\n );\r\n\r\n if (isRootLayout) {\r\n // If this is the root layout, inject our provider after the body tag\r\n return React.Children.map(children, child => {\r\n if (React.isValidElement(child) && child.type === 'html') {\r\n return React.cloneElement(child, {}, \r\n React.Children.map(child.props.children, bodyChild => {\r\n if (React.isValidElement(bodyChild) && bodyChild.type === 'body') {\r\n // Type assertion to access props safely\r\n const bodyProps = bodyChild.props as { children: ReactNode };\r\n return React.cloneElement(bodyChild, {}, \r\n <TernSecureClientProvider>\r\n {bodyProps.children}\r\n </TernSecureClientProvider>\r\n );\r\n }\r\n return bodyChild;\r\n })\r\n );\r\n }\r\n return child;\r\n });\r\n }\r\n\r\n // For non-root layouts, wrap normally\r\n return <TernSecureClientProvider>{children}</TernSecureClientProvider>;\r\n}"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,WAA0B;AACjC,OAAO,aAAa;AA+BJ;AAxBhB,IAAM,2BAA2B;AAAA,EAC/B,MAAM,OAAO,wCAAiD,EAAE,KAAK,SAAO,IAAI,wBAAwB;AAAA,EACxG;AAAA,IACE,KAAK;AAAA;AAAA,EAEP;AACF;AAEO,SAAS,mBAAmB,EAAE,SAAS,GAA4B;AAExE,QAAM,eAAe,MAAM,SAAS,QAAQ,QAAQ,EAAE;AAAA,IACpD,WAAS,MAAM,eAAe,KAAK,KAAK,MAAM,SAAS;AAAA,EACzD;AAEA,MAAI,cAAc;AAEhB,WAAO,MAAM,SAAS,IAAI,UAAU,WAAS;AAC3C,UAAI,MAAM,eAAe,KAAK,KAAK,MAAM,SAAS,QAAQ;AACxD,eAAO,MAAM;AAAA,UAAa;AAAA,UAAO,CAAC;AAAA,UAChC,MAAM,SAAS,IAAI,MAAM,MAAM,UAAU,eAAa;AACpD,gBAAI,MAAM,eAAe,SAAS,KAAK,UAAU,SAAS,QAAQ;AAEhE,oBAAM,YAAY,UAAU;AAC5B,qBAAO,MAAM;AAAA,gBAAa;AAAA,gBAAW,CAAC;AAAA,gBACpC,oBAAC,4BACE,oBAAU,UACb;AAAA,cACF;AAAA,YACF;AACA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAGA,SAAO,oBAAC,4BAA0B,UAAS;AAC7C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|