@tern-secure/nextjs 3.1.27 → 3.1.28

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.
@@ -1,358 +0,0 @@
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 };
@@ -1 +0,0 @@
1
- export { TernSecureClientProvider } from './chunk-BGA4LR4W.js';
@@ -1,6 +0,0 @@
1
- export { TernSecureAuth, TernSecureClientProvider, TernSecureContext, TernSecureFirestore, TernSecureStorage, loadFireConfig, signInWithEmail, useTernSecure, validateConfig } from './app-router/client';
2
- export { TernSecureProvider } from './app-router/server';
3
- export { useAuth } from './hooks/useAuth';
4
- export { SignIn } from './components/sign-in';
5
- //# sourceMappingURL=index.js.map
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
@@ -1,81 +0,0 @@
1
- import * as _firebase_storage from '@firebase/storage';
2
- import * as _firebase_firestore from '@firebase/firestore';
3
- import * as _firebase_auth from '@firebase/auth';
4
- import { UserCredential, User } from 'firebase/auth';
5
- import * as React from 'react';
6
- import React__default, { ReactNode } from 'react';
7
- import * as react_jsx_runtime from 'react/jsx-runtime';
8
-
9
- declare const TernSecureAuth: () => _firebase_auth.Auth;
10
- declare const TernSecureFirestore: () => _firebase_firestore.Firestore;
11
- declare const TernSecureStorage: () => _firebase_storage.FirebaseStorage;
12
-
13
- interface SignInCredentials {
14
- email: string;
15
- password: string;
16
- }
17
- declare function signInWithEmail({ email, password }: SignInCredentials): Promise<UserCredential>;
18
-
19
- interface TernSecureConfig {
20
- apiKey: string;
21
- authDomain: string;
22
- projectId: string;
23
- storageBucket: string;
24
- messagingSenderId: string;
25
- appId: string;
26
- measurementId: string;
27
- }
28
- interface FirebaseState {
29
- initialized: boolean;
30
- error: Error | null;
31
- }
32
- interface TernSecureState {
33
- firebase: FirebaseState;
34
- auth: AuthState;
35
- }
36
- interface AuthState {
37
- user: User | null;
38
- loading: boolean;
39
- error: Error | null;
40
- isSignedIn: boolean;
41
- }
42
-
43
- declare const loadFireConfig: () => TernSecureConfig;
44
- declare const validateConfig: (config: TernSecureConfig) => TernSecureConfig;
45
-
46
- declare const TernSecureContext: React__default.Context<[TernSecureState, React__default.Dispatch<React__default.SetStateAction<TernSecureState>>]>;
47
- declare const useTernSecure: (hookname?: string) => [TernSecureState, React__default.Dispatch<React__default.SetStateAction<TernSecureState>>];
48
-
49
- declare function TernSecureClientProvider({ children }: {
50
- children: React__default.ReactNode;
51
- }): react_jsx_runtime.JSX.Element;
52
-
53
- interface TernSecureProviderProps {
54
- children: ReactNode;
55
- }
56
- declare function TernSecureProvider({ children }: TernSecureProviderProps): react_jsx_runtime.JSX.Element | (string | number | React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode>)[] | null | undefined;
57
-
58
- declare function useAuth(): AuthState;
59
-
60
- interface SignInProps {
61
- onSuccess?: () => void;
62
- onError?: (error: Error) => void;
63
- redirectUrl?: string;
64
- className?: string;
65
- style?: React.CSSProperties;
66
- customStyles?: {
67
- container?: string;
68
- header?: string;
69
- title?: string;
70
- formWrapper?: string;
71
- formContainer?: string;
72
- form?: string;
73
- input?: string;
74
- button?: string;
75
- errorText?: string;
76
- label?: string;
77
- };
78
- }
79
- declare function SignIn({ onSuccess, onError, redirectUrl, className, style, customStyles }: SignInProps): react_jsx_runtime.JSX.Element;
80
-
81
- export { SignIn, TernSecureAuth, TernSecureClientProvider, TernSecureContext, TernSecureFirestore, TernSecureProvider, TernSecureStorage, loadFireConfig, signInWithEmail, useAuth, useTernSecure, validateConfig };
@@ -1,81 +0,0 @@
1
- import * as _firebase_storage from '@firebase/storage';
2
- import * as _firebase_firestore from '@firebase/firestore';
3
- import * as _firebase_auth from '@firebase/auth';
4
- import { UserCredential, User } from 'firebase/auth';
5
- import * as React from 'react';
6
- import React__default, { ReactNode } from 'react';
7
- import * as react_jsx_runtime from 'react/jsx-runtime';
8
-
9
- declare const TernSecureAuth: () => _firebase_auth.Auth;
10
- declare const TernSecureFirestore: () => _firebase_firestore.Firestore;
11
- declare const TernSecureStorage: () => _firebase_storage.FirebaseStorage;
12
-
13
- interface SignInCredentials {
14
- email: string;
15
- password: string;
16
- }
17
- declare function signInWithEmail({ email, password }: SignInCredentials): Promise<UserCredential>;
18
-
19
- interface TernSecureConfig {
20
- apiKey: string;
21
- authDomain: string;
22
- projectId: string;
23
- storageBucket: string;
24
- messagingSenderId: string;
25
- appId: string;
26
- measurementId: string;
27
- }
28
- interface FirebaseState {
29
- initialized: boolean;
30
- error: Error | null;
31
- }
32
- interface TernSecureState {
33
- firebase: FirebaseState;
34
- auth: AuthState;
35
- }
36
- interface AuthState {
37
- user: User | null;
38
- loading: boolean;
39
- error: Error | null;
40
- isSignedIn: boolean;
41
- }
42
-
43
- declare const loadFireConfig: () => TernSecureConfig;
44
- declare const validateConfig: (config: TernSecureConfig) => TernSecureConfig;
45
-
46
- declare const TernSecureContext: React__default.Context<[TernSecureState, React__default.Dispatch<React__default.SetStateAction<TernSecureState>>]>;
47
- declare const useTernSecure: (hookname?: string) => [TernSecureState, React__default.Dispatch<React__default.SetStateAction<TernSecureState>>];
48
-
49
- declare function TernSecureClientProvider({ children }: {
50
- children: React__default.ReactNode;
51
- }): react_jsx_runtime.JSX.Element;
52
-
53
- interface TernSecureProviderProps {
54
- children: ReactNode;
55
- }
56
- declare function TernSecureProvider({ children }: TernSecureProviderProps): react_jsx_runtime.JSX.Element | (string | number | React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode>)[] | null | undefined;
57
-
58
- declare function useAuth(): AuthState;
59
-
60
- interface SignInProps {
61
- onSuccess?: () => void;
62
- onError?: (error: Error) => void;
63
- redirectUrl?: string;
64
- className?: string;
65
- style?: React.CSSProperties;
66
- customStyles?: {
67
- container?: string;
68
- header?: string;
69
- title?: string;
70
- formWrapper?: string;
71
- formContainer?: string;
72
- form?: string;
73
- input?: string;
74
- button?: string;
75
- errorText?: string;
76
- label?: string;
77
- };
78
- }
79
- declare function SignIn({ onSuccess, onError, redirectUrl, className, style, customStyles }: SignInProps): react_jsx_runtime.JSX.Element;
80
-
81
- export { SignIn, TernSecureAuth, TernSecureClientProvider, TernSecureContext, TernSecureFirestore, TernSecureProvider, TernSecureStorage, loadFireConfig, signInWithEmail, useAuth, useTernSecure, validateConfig };
package/dist/esm/index.js DELETED
@@ -1,59 +0,0 @@
1
- 'use strict';
2
-
3
- var client = require('./app-router/client');
4
- var server = require('./app-router/server');
5
- var useAuth = require('./hooks/useAuth');
6
- var signIn = require('./components/sign-in');
7
-
8
-
9
-
10
- Object.defineProperty(exports, "TernSecureAuth", {
11
- enumerable: true,
12
- get: function () { return client.TernSecureAuth; }
13
- });
14
- Object.defineProperty(exports, "TernSecureClientProvider", {
15
- enumerable: true,
16
- get: function () { return client.TernSecureClientProvider; }
17
- });
18
- Object.defineProperty(exports, "TernSecureContext", {
19
- enumerable: true,
20
- get: function () { return client.TernSecureContext; }
21
- });
22
- Object.defineProperty(exports, "TernSecureFirestore", {
23
- enumerable: true,
24
- get: function () { return client.TernSecureFirestore; }
25
- });
26
- Object.defineProperty(exports, "TernSecureStorage", {
27
- enumerable: true,
28
- get: function () { return client.TernSecureStorage; }
29
- });
30
- Object.defineProperty(exports, "loadFireConfig", {
31
- enumerable: true,
32
- get: function () { return client.loadFireConfig; }
33
- });
34
- Object.defineProperty(exports, "signInWithEmail", {
35
- enumerable: true,
36
- get: function () { return client.signInWithEmail; }
37
- });
38
- Object.defineProperty(exports, "useTernSecure", {
39
- enumerable: true,
40
- get: function () { return client.useTernSecure; }
41
- });
42
- Object.defineProperty(exports, "validateConfig", {
43
- enumerable: true,
44
- get: function () { return client.validateConfig; }
45
- });
46
- Object.defineProperty(exports, "TernSecureProvider", {
47
- enumerable: true,
48
- get: function () { return server.TernSecureProvider; }
49
- });
50
- Object.defineProperty(exports, "useAuth", {
51
- enumerable: true,
52
- get: function () { return useAuth.useAuth; }
53
- });
54
- Object.defineProperty(exports, "SignIn", {
55
- enumerable: true,
56
- get: function () { return signIn.SignIn; }
57
- });
58
- //# sourceMappingURL=index.js.map
59
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
@@ -1,33 +0,0 @@
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 };