@tern-secure/nextjs 1.9.0 → 1.9.2
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 +63 -11
- 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 +25 -13
- package/dist/app-router/server/providers/TernSecureServerProvider.js.map +1 -1
- package/dist/hooks/useAuth.d.ts +7 -2
- package/dist/hooks/useAuth.js +4 -23
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/types/ternsecure.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AuthState } from '../../../types/ternsecure';
|
|
3
|
+
export declare const useTernSecure: () => AuthState;
|
|
3
4
|
interface TernSecureClientProps {
|
|
4
5
|
children: React.ReactNode;
|
|
5
|
-
initialState: AuthState;
|
|
6
6
|
}
|
|
7
|
-
export declare function TernSecureClientProvider({ children
|
|
7
|
+
export declare function TernSecureClientProvider({ children }: TernSecureClientProps): React.JSX.Element;
|
|
8
8
|
export {};
|
|
@@ -1,17 +1,69 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
3
3
|
import { getTernSecureAuth } from '../client-init';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// Move context creation inside the client component
|
|
5
|
+
const createTernSecureContext = () => {
|
|
6
|
+
const initialAuthState = {
|
|
7
|
+
user: null,
|
|
8
|
+
loading: true,
|
|
9
|
+
error: null,
|
|
10
|
+
initialized: false,
|
|
11
|
+
isSignedIn: false
|
|
12
|
+
};
|
|
13
|
+
return createContext(initialAuthState);
|
|
14
|
+
};
|
|
15
|
+
// Create context lazily only on client side
|
|
16
|
+
const TernSecureContext = createTernSecureContext();
|
|
17
|
+
export const useTernSecure = () => {
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
throw new Error('useTernSecure can only be used in client components');
|
|
20
|
+
}
|
|
21
|
+
const context = useContext(TernSecureContext);
|
|
22
|
+
if (!context) {
|
|
23
|
+
throw new Error('useTernSecure must be used within TernSecureClientProvider');
|
|
24
|
+
}
|
|
25
|
+
return context;
|
|
26
|
+
};
|
|
27
|
+
export function TernSecureClientProvider({ children }) {
|
|
28
|
+
const [authState, setAuthState] = useState({
|
|
29
|
+
user: null,
|
|
30
|
+
loading: true,
|
|
31
|
+
error: null,
|
|
32
|
+
initialized: false,
|
|
33
|
+
isSignedIn: false
|
|
34
|
+
});
|
|
6
35
|
useEffect(() => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
36
|
+
try {
|
|
37
|
+
const auth = getTernSecureAuth();
|
|
38
|
+
const unsubscribe = auth.onAuthStateChanged((user) => {
|
|
39
|
+
setAuthState({
|
|
40
|
+
user,
|
|
41
|
+
loading: false,
|
|
42
|
+
error: null,
|
|
43
|
+
initialized: true,
|
|
44
|
+
isSignedIn: !!user
|
|
45
|
+
});
|
|
46
|
+
}, (error) => {
|
|
47
|
+
setAuthState({
|
|
48
|
+
user: null,
|
|
49
|
+
loading: false,
|
|
50
|
+
error,
|
|
51
|
+
initialized: true,
|
|
52
|
+
isSignedIn: false
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return () => unsubscribe();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
setAuthState({
|
|
59
|
+
user: null,
|
|
60
|
+
loading: false,
|
|
61
|
+
error: error,
|
|
62
|
+
initialized: true,
|
|
63
|
+
isSignedIn: false
|
|
64
|
+
});
|
|
65
|
+
}
|
|
14
66
|
}, []);
|
|
15
|
-
return children;
|
|
67
|
+
return (React.createElement(TernSecureContext.Provider, { value: authState }, children));
|
|
16
68
|
}
|
|
17
69
|
//# 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,
|
|
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,gBAAgB,GAAc;QAClC,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,KAAK;QAClB,UAAU,EAAE,KAAK;KAClB,CAAA;IAED,OAAO,aAAa,CAAY,gBAAgB,CAAC,CAAA;AACnD,CAAC,CAAA;AAED,4CAA4C;AAC5C,MAAM,iBAAiB,GAAG,uBAAuB,EAAE,CAAA;AAEnD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;IACxE,CAAC;IAED,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAC7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAA;IAC/E,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAMD,MAAM,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|
2
2
|
interface TernSecureProviderProps {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
}
|
|
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,18 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import dynamic from 'next/dynamic';
|
|
3
|
+
// Dynamically import the client provider with no SSR
|
|
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
|
+
});
|
|
2
8
|
export function TernSecureProvider({ children }) {
|
|
3
|
-
if
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
});
|
|
16
26
|
}
|
|
27
|
+
// For non-root layouts, wrap normally
|
|
28
|
+
return React.createElement(TernSecureClientProvider, null, children);
|
|
17
29
|
}
|
|
18
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;
|
|
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
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare function useAuth(): {
|
|
2
|
+
user: import("@firebase/auth").User | null;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
error: Error | null;
|
|
5
|
+
initialized: boolean;
|
|
6
|
+
isSignedIn: boolean;
|
|
7
|
+
};
|
package/dist/hooks/useAuth.js
CHANGED
|
@@ -1,38 +1,19 @@
|
|
|
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
|
-
initialized: false
|
|
8
|
+
initialized: false,
|
|
9
|
+
isSignedIn: false,
|
|
11
10
|
});
|
|
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
11
|
return {
|
|
31
12
|
user: authState.user,
|
|
32
13
|
loading: authState.loading,
|
|
33
14
|
error: authState.error,
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
initialized: authState.initialized,
|
|
16
|
+
isSignedIn: authState.isSignedIn,
|
|
36
17
|
};
|
|
37
18
|
}
|
|
38
19
|
//# 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,WAAW,EAAE,KAAK;QAClB,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,WAAW,EAAE,SAAS,CAAC,WAAW;QAClC,UAAU,EAAE,SAAS,CAAC,UAAU;KACjC,CAAC;AACJ,CAAC"}
|