@tern-secure/nextjs 3.1.28 → 3.1.30
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/client/chunk-BGA4LR4W.js +32 -0
- package/dist/client/index.cjs +431 -0
- package/dist/client/index.js +358 -0
- package/dist/client/ternSecureClientProvider-5BLRLQMH.js +1 -0
- package/dist/server/chunk-AHVNPKXU.js +33 -0
- package/dist/server/index.cjs +431 -0
- package/dist/server/index.d.cts +81 -0
- package/dist/server/index.d.ts +81 -0
- package/dist/server/index.js +358 -0
- package/dist/server/ternSecureClientProvider-P663N3F7.js +1 -0
- package/package.json +1 -1
- package/dist/index.cjs +0 -59
- package/dist/index.cjs.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- /package/dist/{index.d.cts → client/index.d.cts} +0 -0
- /package/dist/{index.d.ts → client/index.d.ts} +0 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { useTernSecure } from './chunk-BGA4LR4W.js';
|
|
2
|
+
export { TernSecureClientProvider, TernSecureContext, useTernSecure } from './chunk-BGA4LR4W.js';
|
|
3
|
+
import { getApps, initializeApp } from 'firebase/app';
|
|
4
|
+
import { getAuth, setPersistence, browserSessionPersistence, signInWithEmailAndPassword } from 'firebase/auth';
|
|
5
|
+
import { getFirestore } from 'firebase/firestore';
|
|
6
|
+
import { getStorage } from 'firebase/storage';
|
|
7
|
+
import React, { useEffect, useState } from 'react';
|
|
8
|
+
import dynamic from 'next/dynamic';
|
|
9
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
// src/app-router/client/config.ts
|
|
12
|
+
var loadFireConfig = () => ({
|
|
13
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
|
|
14
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
|
|
15
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
|
16
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
|
|
17
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
|
18
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
|
|
19
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
|
|
20
|
+
});
|
|
21
|
+
var validateConfig = (config) => {
|
|
22
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
23
|
+
if (!value) {
|
|
24
|
+
throw new Error(`Missing environment variable: NEXT_PUBLIC_FIREBASE_${key.toUpperCase()}`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return config;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/app-router/client/client-init.ts
|
|
31
|
+
var app = (() => {
|
|
32
|
+
const config = validateConfig(loadFireConfig());
|
|
33
|
+
return getApps().length ? getApps()[0] : initializeApp(config);
|
|
34
|
+
})();
|
|
35
|
+
var auth = getAuth(app);
|
|
36
|
+
setPersistence(auth, browserSessionPersistence);
|
|
37
|
+
var firestore = getFirestore(app);
|
|
38
|
+
var storage = getStorage(app);
|
|
39
|
+
var TernSecureAuth = () => auth;
|
|
40
|
+
var TernSecureFirestore = () => firestore;
|
|
41
|
+
var TernSecureStorage = () => storage;
|
|
42
|
+
async function signInWithEmail({
|
|
43
|
+
email,
|
|
44
|
+
password
|
|
45
|
+
}) {
|
|
46
|
+
const auth2 = TernSecureAuth();
|
|
47
|
+
return signInWithEmailAndPassword(auth2, email, password);
|
|
48
|
+
}
|
|
49
|
+
var TernSecureClientProvider2 = dynamic(
|
|
50
|
+
() => import('./ternSecureClientProvider-5BLRLQMH.js').then((mod) => mod.TernSecureClientProvider),
|
|
51
|
+
{
|
|
52
|
+
ssr: false
|
|
53
|
+
//loading: () => null // Return null or a loading indicator
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
function TernSecureProvider({ children }) {
|
|
57
|
+
const isRootLayout = React.Children.toArray(children).some(
|
|
58
|
+
(child) => React.isValidElement(child) && child.type === "html"
|
|
59
|
+
);
|
|
60
|
+
if (isRootLayout) {
|
|
61
|
+
return React.Children.map(children, (child) => {
|
|
62
|
+
if (React.isValidElement(child) && child.type === "html") {
|
|
63
|
+
return React.cloneElement(
|
|
64
|
+
child,
|
|
65
|
+
{},
|
|
66
|
+
React.Children.map(child.props.children, (bodyChild) => {
|
|
67
|
+
if (React.isValidElement(bodyChild) && bodyChild.type === "body") {
|
|
68
|
+
const bodyProps = bodyChild.props;
|
|
69
|
+
return React.cloneElement(
|
|
70
|
+
bodyChild,
|
|
71
|
+
{},
|
|
72
|
+
/* @__PURE__ */ jsx(TernSecureClientProvider2, { children: bodyProps.children })
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return bodyChild;
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return child;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ jsx(TernSecureClientProvider2, { children });
|
|
83
|
+
}
|
|
84
|
+
function useAuth() {
|
|
85
|
+
const [state, setState] = useTernSecure("useAuth");
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
try {
|
|
88
|
+
const auth2 = TernSecureAuth();
|
|
89
|
+
setState((prev) => ({
|
|
90
|
+
...prev,
|
|
91
|
+
firebase: {
|
|
92
|
+
initialized: true,
|
|
93
|
+
error: null
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
const unsubscribe = auth2.onAuthStateChanged(
|
|
97
|
+
(user) => {
|
|
98
|
+
setState((prev) => ({
|
|
99
|
+
...prev,
|
|
100
|
+
auth: {
|
|
101
|
+
user,
|
|
102
|
+
loading: false,
|
|
103
|
+
error: null,
|
|
104
|
+
isSignedIn: !!user
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
},
|
|
108
|
+
(error) => {
|
|
109
|
+
setState((prev) => ({
|
|
110
|
+
...prev,
|
|
111
|
+
auth: {
|
|
112
|
+
user: null,
|
|
113
|
+
loading: false,
|
|
114
|
+
error,
|
|
115
|
+
isSignedIn: false
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
return () => unsubscribe();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
setState((prev) => ({
|
|
123
|
+
...prev,
|
|
124
|
+
firebase: {
|
|
125
|
+
initialized: false,
|
|
126
|
+
error
|
|
127
|
+
},
|
|
128
|
+
auth: {
|
|
129
|
+
user: null,
|
|
130
|
+
loading: false,
|
|
131
|
+
error,
|
|
132
|
+
isSignedIn: false
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
}, []);
|
|
137
|
+
return state.auth;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/utils/create-styles.ts
|
|
141
|
+
var PREFIX = "tern";
|
|
142
|
+
var styleInjection = {
|
|
143
|
+
isInjected: false,
|
|
144
|
+
styleElement: null
|
|
145
|
+
};
|
|
146
|
+
var defaultClassNames = {
|
|
147
|
+
container: `${PREFIX}-container`,
|
|
148
|
+
header: `${PREFIX}-header`,
|
|
149
|
+
title: `${PREFIX}-title`,
|
|
150
|
+
formWrapper: `${PREFIX}-formWrapper`,
|
|
151
|
+
formContainer: `${PREFIX}-formContainer`,
|
|
152
|
+
form: `${PREFIX}-form`,
|
|
153
|
+
label: `${PREFIX}-label`,
|
|
154
|
+
input: `${PREFIX}-input`,
|
|
155
|
+
button: `${PREFIX}-button`,
|
|
156
|
+
error: `${PREFIX}-error`
|
|
157
|
+
};
|
|
158
|
+
function createStyleSheet(styles2) {
|
|
159
|
+
if (typeof window === "undefined") return defaultClassNames;
|
|
160
|
+
if (styleInjection.isInjected) {
|
|
161
|
+
return defaultClassNames;
|
|
162
|
+
}
|
|
163
|
+
let styleElement = document.querySelector("[data-tern-secure]");
|
|
164
|
+
if (!styleElement) {
|
|
165
|
+
styleElement = document.createElement("style");
|
|
166
|
+
styleElement.setAttribute("data-tern-secure", "");
|
|
167
|
+
document.head.appendChild(styleElement);
|
|
168
|
+
styleInjection.styleElement = styleElement;
|
|
169
|
+
}
|
|
170
|
+
const cssRules = Object.entries(styles2).map(([key, rules]) => {
|
|
171
|
+
const className = defaultClassNames[key];
|
|
172
|
+
const cssProperties = Object.entries(rules).map(([prop, value]) => {
|
|
173
|
+
const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
174
|
+
return `${cssProperty}: ${value};`;
|
|
175
|
+
}).join(" ");
|
|
176
|
+
return `.${className} { ${cssProperties} }`;
|
|
177
|
+
}).join("\n");
|
|
178
|
+
styleElement.textContent = cssRules;
|
|
179
|
+
styleInjection.isInjected = true;
|
|
180
|
+
return defaultClassNames;
|
|
181
|
+
}
|
|
182
|
+
var styleConfig = {
|
|
183
|
+
container: {
|
|
184
|
+
display: "flex",
|
|
185
|
+
minHeight: "100%",
|
|
186
|
+
flex: "1",
|
|
187
|
+
flexDirection: "column",
|
|
188
|
+
justifyContent: "center",
|
|
189
|
+
padding: "3rem 1.5rem"
|
|
190
|
+
},
|
|
191
|
+
header: {
|
|
192
|
+
margin: "0 auto",
|
|
193
|
+
width: "100%",
|
|
194
|
+
maxWidth: "28rem"
|
|
195
|
+
},
|
|
196
|
+
title: {
|
|
197
|
+
marginTop: "1.5rem",
|
|
198
|
+
textAlign: "center",
|
|
199
|
+
fontSize: "1.875rem",
|
|
200
|
+
fontWeight: "700",
|
|
201
|
+
lineHeight: "2.25rem",
|
|
202
|
+
letterSpacing: "-0.025em",
|
|
203
|
+
color: "var(--tern-text-primary, #111827)"
|
|
204
|
+
},
|
|
205
|
+
formWrapper: {
|
|
206
|
+
marginTop: "2.5rem",
|
|
207
|
+
margin: "0 auto",
|
|
208
|
+
width: "100%",
|
|
209
|
+
maxWidth: "30rem"
|
|
210
|
+
},
|
|
211
|
+
formContainer: {
|
|
212
|
+
padding: "3rem 1.5rem",
|
|
213
|
+
boxShadow: "0 1px 3px 0 rgb(0 0 0 / 0.1)",
|
|
214
|
+
borderRadius: "0.5rem",
|
|
215
|
+
backgroundColor: "var(--tern-background, white)"
|
|
216
|
+
},
|
|
217
|
+
form: {
|
|
218
|
+
display: "flex",
|
|
219
|
+
flexDirection: "column",
|
|
220
|
+
gap: "1rem"
|
|
221
|
+
},
|
|
222
|
+
label: {
|
|
223
|
+
display: "block",
|
|
224
|
+
fontSize: "0.875rem",
|
|
225
|
+
fontWeight: "500",
|
|
226
|
+
color: "var(--tern-text-secondary, #374151)"
|
|
227
|
+
},
|
|
228
|
+
input: {
|
|
229
|
+
marginTop: "0.25rem",
|
|
230
|
+
display: "block",
|
|
231
|
+
width: "100%",
|
|
232
|
+
padding: "0.5rem 0.75rem",
|
|
233
|
+
borderRadius: "0.375rem",
|
|
234
|
+
border: "1px solid var(--tern-border, #D1D5DB)",
|
|
235
|
+
backgroundColor: "var(--tern-input-background, white)",
|
|
236
|
+
color: "var(--tern-text-primary, #111827)"
|
|
237
|
+
},
|
|
238
|
+
button: {
|
|
239
|
+
display: "flex",
|
|
240
|
+
width: "100%",
|
|
241
|
+
justifyContent: "center",
|
|
242
|
+
padding: "0.5rem 1rem",
|
|
243
|
+
fontSize: "0.875rem",
|
|
244
|
+
fontWeight: "500",
|
|
245
|
+
color: "white",
|
|
246
|
+
backgroundColor: "var(--tern-primary, #2563EB)",
|
|
247
|
+
border: "none",
|
|
248
|
+
borderRadius: "0.375rem",
|
|
249
|
+
cursor: "pointer"
|
|
250
|
+
},
|
|
251
|
+
error: {
|
|
252
|
+
color: "var(--tern-error, #DC2626)",
|
|
253
|
+
fontSize: "0.875rem"
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var styles = createStyleSheet(styleConfig);
|
|
257
|
+
function SignIn({
|
|
258
|
+
onSuccess,
|
|
259
|
+
onError,
|
|
260
|
+
redirectUrl,
|
|
261
|
+
className = "",
|
|
262
|
+
style,
|
|
263
|
+
customStyles = {}
|
|
264
|
+
}) {
|
|
265
|
+
const [email, setEmail] = useState("");
|
|
266
|
+
const [password, setPassword] = useState("");
|
|
267
|
+
const [loading, setLoading] = useState(false);
|
|
268
|
+
const [error, setError] = useState("");
|
|
269
|
+
const handleSubmit = async (e) => {
|
|
270
|
+
e.preventDefault();
|
|
271
|
+
setLoading(true);
|
|
272
|
+
setError("");
|
|
273
|
+
try {
|
|
274
|
+
await signInWithEmail({ email, password });
|
|
275
|
+
onSuccess?.();
|
|
276
|
+
if (redirectUrl) {
|
|
277
|
+
window.location.href = redirectUrl;
|
|
278
|
+
}
|
|
279
|
+
} catch (err) {
|
|
280
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to sign in";
|
|
281
|
+
setError(errorMessage);
|
|
282
|
+
onError?.(err instanceof Error ? err : new Error("Failed to sign in"));
|
|
283
|
+
} finally {
|
|
284
|
+
setLoading(false);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
return /* @__PURE__ */ jsxs("div", { className: `${styles.container} ${customStyles.container || ""}`, style, children: [
|
|
288
|
+
/* @__PURE__ */ jsx("div", { className: `${styles.header} ${customStyles.header || ""}`, children: /* @__PURE__ */ jsx("h2", { className: `${styles.title} ${customStyles.title || ""}`, children: "Sign in to your account" }) }),
|
|
289
|
+
/* @__PURE__ */ jsx("div", { className: `${styles.formWrapper} ${customStyles.formWrapper || ""}`, children: /* @__PURE__ */ jsx("div", { className: `${styles.formContainer} ${customStyles.formContainer || ""}`, children: /* @__PURE__ */ jsxs(
|
|
290
|
+
"form",
|
|
291
|
+
{
|
|
292
|
+
onSubmit: handleSubmit,
|
|
293
|
+
className: `${styles.form} ${customStyles.form || ""} ${className}`,
|
|
294
|
+
role: "form",
|
|
295
|
+
"aria-label": "Sign in form",
|
|
296
|
+
children: [
|
|
297
|
+
error && /* @__PURE__ */ jsx(
|
|
298
|
+
"div",
|
|
299
|
+
{
|
|
300
|
+
className: `${styles.error} ${customStyles.errorText || ""}`,
|
|
301
|
+
role: "alert",
|
|
302
|
+
"aria-live": "polite",
|
|
303
|
+
children: error
|
|
304
|
+
}
|
|
305
|
+
),
|
|
306
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
307
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "email", className: `${styles.label} ${customStyles.label || ""}`, children: "Email" }),
|
|
308
|
+
/* @__PURE__ */ jsx(
|
|
309
|
+
"input",
|
|
310
|
+
{
|
|
311
|
+
id: "email",
|
|
312
|
+
type: "email",
|
|
313
|
+
value: email,
|
|
314
|
+
onChange: (e) => setEmail(e.target.value),
|
|
315
|
+
placeholder: "Enter your email",
|
|
316
|
+
required: true,
|
|
317
|
+
className: `${styles.input} ${customStyles.input || ""}`,
|
|
318
|
+
disabled: loading,
|
|
319
|
+
"aria-required": "true",
|
|
320
|
+
"aria-invalid": !!error
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
] }),
|
|
324
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
325
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "password", className: `${styles.label} ${customStyles.label || ""}`, children: "Password" }),
|
|
326
|
+
/* @__PURE__ */ jsx(
|
|
327
|
+
"input",
|
|
328
|
+
{
|
|
329
|
+
id: "password",
|
|
330
|
+
type: "password",
|
|
331
|
+
value: password,
|
|
332
|
+
onChange: (e) => setPassword(e.target.value),
|
|
333
|
+
placeholder: "Enter your password",
|
|
334
|
+
required: true,
|
|
335
|
+
className: `${styles.input} ${customStyles.input || ""}`,
|
|
336
|
+
disabled: loading,
|
|
337
|
+
"aria-required": "true",
|
|
338
|
+
"aria-invalid": !!error
|
|
339
|
+
}
|
|
340
|
+
)
|
|
341
|
+
] }),
|
|
342
|
+
/* @__PURE__ */ jsx(
|
|
343
|
+
"button",
|
|
344
|
+
{
|
|
345
|
+
type: "submit",
|
|
346
|
+
disabled: loading,
|
|
347
|
+
className: `${styles.button} ${customStyles.button || ""}`,
|
|
348
|
+
"data-testid": "sign-in-submit",
|
|
349
|
+
children: loading ? "Signing in..." : "Sign in"
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
) }) })
|
|
355
|
+
] });
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export { SignIn, TernSecureAuth, TernSecureFirestore, TernSecureProvider, TernSecureStorage, loadFireConfig, signInWithEmail, useAuth, validateConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TernSecureClientProvider } from './chunk-BGA4LR4W.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/app-router/client/providers/ternSecureClientProvider.tsx
|
|
5
|
+
var initialState = {
|
|
6
|
+
firebase: {
|
|
7
|
+
initialized: false,
|
|
8
|
+
error: null
|
|
9
|
+
},
|
|
10
|
+
auth: {
|
|
11
|
+
user: null,
|
|
12
|
+
loading: true,
|
|
13
|
+
error: null,
|
|
14
|
+
isSignedIn: false
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var TernSecureContext = React.createContext([initialState, () => {
|
|
18
|
+
}]);
|
|
19
|
+
var useTernSecure = (hookname) => {
|
|
20
|
+
const context = React.useContext(TernSecureContext);
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`${hookname} must be used within TernSecureProvider`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return context;
|
|
27
|
+
};
|
|
28
|
+
function TernSecureClientProvider({ children }) {
|
|
29
|
+
const stateAndUpdater = useState(initialState);
|
|
30
|
+
return /* @__PURE__ */ jsx(TernSecureContext.Provider, { value: stateAndUpdater, children });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { TernSecureClientProvider, TernSecureContext, useTernSecure };
|