@tern-secure/nextjs 1.9.1 → 1.9.3
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/app-router/client/providers/ternSecureClientProvider.d.ts +2 -2
- package/dist/app-router/client/providers/ternSecureClientProvider.js +62 -30
- package/dist/app-router/client/providers/ternSecureClientProvider.js.map +1 -1
- package/dist/app-router/server/providers/TernSecureServerProvider.d.ts +1 -1
- package/dist/app-router/server/providers/TernSecureServerProvider.js +23 -1
- package/dist/app-router/server/providers/TernSecureServerProvider.js.map +1 -1
- package/dist/hooks/useAuth.d.ts +6 -2
- package/dist/hooks/useAuth.js +2 -23
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/types/ternsecure.d.ts +9 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export declare const useTernSecure: () =>
|
|
2
|
+
import { TernSecureState } from '../../../types/ternsecure';
|
|
3
|
+
export declare const useTernSecure: () => TernSecureState;
|
|
4
4
|
interface TernSecureClientProps {
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
}
|
|
@@ -3,13 +3,19 @@ import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
|
3
3
|
import { getTernSecureAuth } from '../client-init';
|
|
4
4
|
// Move context creation inside the client component
|
|
5
5
|
const createTernSecureContext = () => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const initialState = {
|
|
7
|
+
firebase: {
|
|
8
|
+
initialized: false,
|
|
9
|
+
error: null
|
|
10
|
+
},
|
|
11
|
+
auth: {
|
|
12
|
+
user: null,
|
|
13
|
+
loading: true,
|
|
14
|
+
error: null,
|
|
15
|
+
isSignedIn: false
|
|
16
|
+
}
|
|
11
17
|
};
|
|
12
|
-
return createContext(
|
|
18
|
+
return createContext(initialState);
|
|
13
19
|
};
|
|
14
20
|
// Create context lazily only on client side
|
|
15
21
|
const TernSecureContext = createTernSecureContext();
|
|
@@ -24,41 +30,67 @@ export const useTernSecure = () => {
|
|
|
24
30
|
return context;
|
|
25
31
|
};
|
|
26
32
|
export function TernSecureClientProvider({ children }) {
|
|
27
|
-
const [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
const [state, setState] = useState({
|
|
34
|
+
firebase: {
|
|
35
|
+
initialized: false,
|
|
36
|
+
error: null
|
|
37
|
+
},
|
|
38
|
+
auth: {
|
|
39
|
+
user: null,
|
|
40
|
+
loading: true,
|
|
41
|
+
error: null,
|
|
42
|
+
isSignedIn: false
|
|
43
|
+
}
|
|
32
44
|
});
|
|
33
45
|
useEffect(() => {
|
|
34
46
|
try {
|
|
35
47
|
const auth = getTernSecureAuth();
|
|
48
|
+
setState(prev => ({
|
|
49
|
+
...prev,
|
|
50
|
+
firebase: {
|
|
51
|
+
initialized: true,
|
|
52
|
+
error: null
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
36
55
|
const unsubscribe = auth.onAuthStateChanged((user) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
setState(prev => ({
|
|
57
|
+
...prev,
|
|
58
|
+
auth: {
|
|
59
|
+
user,
|
|
60
|
+
loading: false,
|
|
61
|
+
error: null,
|
|
62
|
+
isSignedIn: !!user
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
43
65
|
}, (error) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
66
|
+
setState(prev => ({
|
|
67
|
+
...prev,
|
|
68
|
+
auth: {
|
|
69
|
+
user: null,
|
|
70
|
+
loading: false,
|
|
71
|
+
error,
|
|
72
|
+
isSignedIn: false
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
50
75
|
});
|
|
51
76
|
return () => unsubscribe();
|
|
52
77
|
}
|
|
53
78
|
catch (error) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
setState(prev => ({
|
|
80
|
+
...prev,
|
|
81
|
+
firebase: {
|
|
82
|
+
initialized: false,
|
|
83
|
+
error: error
|
|
84
|
+
},
|
|
85
|
+
auth: {
|
|
86
|
+
user: null,
|
|
87
|
+
loading: false,
|
|
88
|
+
error: error,
|
|
89
|
+
isSignedIn: false
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
60
92
|
}
|
|
61
93
|
}, []);
|
|
62
|
-
return (React.createElement(TernSecureContext.Provider, { value:
|
|
94
|
+
return (React.createElement(TernSecureContext.Provider, { value: state }, children));
|
|
63
95
|
}
|
|
64
96
|
//# sourceMappingURL=ternSecureClientProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ternSecureClientProvider.js","sourceRoot":"","sources":["../../../../src/app-router/client/providers/ternSecureClientProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGlD,oDAAoD;AACpD,MAAM,uBAAuB,GAAG,GAAG,EAAE;IACnC,MAAM,
|
|
1
|
+
{"version":3,"file":"ternSecureClientProvider.js","sourceRoot":"","sources":["../../../../src/app-router/client/providers/ternSecureClientProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGlD,oDAAoD;AACpD,MAAM,uBAAuB,GAAG,GAAG,EAAE;IACnC,MAAM,YAAY,GAAoB;QAC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|
5
|
-
export declare function TernSecureProvider({ children }: TernSecureProviderProps): React.JSX.Element;
|
|
5
|
+
export declare function TernSecureProvider({ children }: TernSecureProviderProps): React.JSX.Element | (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>)[] | null | undefined;
|
|
6
6
|
export {};
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import dynamic from 'next/dynamic';
|
|
3
3
|
// Dynamically import the client provider with no SSR
|
|
4
|
-
const TernSecureClientProvider = dynamic(() => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider), {
|
|
4
|
+
const TernSecureClientProvider = dynamic(() => import('../../client/providers/ternSecureClientProvider').then(mod => mod.TernSecureClientProvider), {
|
|
5
|
+
ssr: false,
|
|
6
|
+
loading: () => null // Return null or a loading indicator
|
|
7
|
+
});
|
|
5
8
|
export function TernSecureProvider({ children }) {
|
|
9
|
+
// Check if the children contain html/body tags
|
|
10
|
+
const isRootLayout = React.Children.toArray(children).some(child => React.isValidElement(child) && child.type === 'html');
|
|
11
|
+
if (isRootLayout) {
|
|
12
|
+
// If this is the root layout, inject our provider after the body tag
|
|
13
|
+
return React.Children.map(children, child => {
|
|
14
|
+
if (React.isValidElement(child) && child.type === 'html') {
|
|
15
|
+
return React.cloneElement(child, {}, React.Children.map(child.props.children, bodyChild => {
|
|
16
|
+
if (React.isValidElement(bodyChild) && bodyChild.type === 'body') {
|
|
17
|
+
// Type assertion to access props safely
|
|
18
|
+
const bodyProps = bodyChild.props;
|
|
19
|
+
return React.cloneElement(bodyChild, {}, React.createElement(TernSecureClientProvider, null, bodyProps.children));
|
|
20
|
+
}
|
|
21
|
+
return bodyChild;
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
return child;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// For non-root layouts, wrap normally
|
|
6
28
|
return React.createElement(TernSecureClientProvider, null, children);
|
|
7
29
|
}
|
|
8
30
|
//# sourceMappingURL=TernSecureServerProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TernSecureServerProvider.js","sourceRoot":"","sources":["../../../../src/app-router/server/providers/TernSecureServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAA;AAMlC,qDAAqD;AACrD,MAAM,wBAAwB,GAAG,OAAO,CACtC,GAAG,EAAE,CAAC,MAAM,CAAC,iDAAiD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,wBAAwB,CAAC,EACzG,
|
|
1
|
+
{"version":3,"file":"TernSecureServerProvider.js","sourceRoot":"","sources":["../../../../src/app-router/server/providers/TernSecureServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAA;AAMlC,qDAAqD;AACrD,MAAM,wBAAwB,GAAG,OAAO,CACtC,GAAG,EAAE,CAAC,MAAM,CAAC,iDAAiD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,wBAAwB,CAAC,EACzG;IACE,GAAG,EAAE,KAAK;IACV,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,qCAAqC;CAC1D,CACF,CAAA;AAED,MAAM,UAAU,kBAAkB,CAAC,EAAE,QAAQ,EAA2B;IACtE,+CAA+C;IAC/C,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CACxD,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAC9D,CAAC;IAEF,IAAI,YAAY,EAAE,CAAC;QACjB,qEAAqE;QACrE,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE;YAC1C,IAAI,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBACzD,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,EACjC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE;oBACnD,IAAI,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;wBACjE,wCAAwC;wBACxC,MAAM,SAAS,GAAG,SAAS,CAAC,KAAgC,CAAC;wBAC7D,OAAO,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,EACrC,oBAAC,wBAAwB,QACtB,SAAS,CAAC,QAAQ,CACM,CAC5B,CAAC;oBACJ,CAAC;oBACD,OAAO,SAAS,CAAC;gBACnB,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED,sCAAsC;IACtC,OAAO,oBAAC,wBAAwB,QAAE,QAAQ,CAA4B,CAAC;AACzE,CAAC"}
|
package/dist/hooks/useAuth.d.ts
CHANGED
package/dist/hooks/useAuth.js
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { getTernSecureAuth } from '../app-router/client/client-init';
|
|
4
|
-
import { signInWithEmailAndPassword } from 'firebase/auth';
|
|
5
3
|
export function useAuth() {
|
|
6
4
|
const [authState, setAuthState] = useState({
|
|
7
5
|
user: null,
|
|
8
6
|
loading: true,
|
|
9
7
|
error: null,
|
|
10
|
-
|
|
8
|
+
isSignedIn: false,
|
|
11
9
|
});
|
|
12
|
-
const auth = getTernSecureAuth();
|
|
13
|
-
const signIn = async (email, password) => {
|
|
14
|
-
try {
|
|
15
|
-
const userCredential = await signInWithEmailAndPassword(auth, email, password);
|
|
16
|
-
return userCredential.user;
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
throw new Error('Failed to sign in: ' + error.message);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const signOut = async () => {
|
|
23
|
-
try {
|
|
24
|
-
await auth.signOut();
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
throw new Error('Failed to sign out: ' + error.message);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
10
|
return {
|
|
31
11
|
user: authState.user,
|
|
32
12
|
loading: authState.loading,
|
|
33
13
|
error: authState.error,
|
|
34
|
-
|
|
35
|
-
signOut,
|
|
14
|
+
isSignedIn: authState.isSignedIn,
|
|
36
15
|
};
|
|
37
16
|
}
|
|
38
17
|
//# sourceMappingURL=useAuth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIjC,MAAM,UAAU,OAAO;IACrB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAY;QACpD,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,KAAK;KAClB,CAAC,CAAC;IAGH,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,UAAU,EAAE,SAAS,CAAC,UAAU;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -13,11 +13,19 @@ export interface TernSecureOptions {
|
|
|
13
13
|
environment?: 'development' | 'production';
|
|
14
14
|
region?: string;
|
|
15
15
|
}
|
|
16
|
+
export interface FirebaseState {
|
|
17
|
+
initialized: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
}
|
|
20
|
+
export interface TernSecureState {
|
|
21
|
+
firebase: FirebaseState;
|
|
22
|
+
auth: AuthState;
|
|
23
|
+
}
|
|
16
24
|
export interface AuthState {
|
|
17
25
|
user: User | null;
|
|
18
26
|
loading: boolean;
|
|
19
27
|
error: Error | null;
|
|
20
|
-
|
|
28
|
+
isSignedIn: boolean;
|
|
21
29
|
}
|
|
22
30
|
export interface TernSecureContextValue {
|
|
23
31
|
_contextKey: symbol;
|