@tern-secure/nextjs 4.0.0 → 4.1.0

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.
Files changed (96) hide show
  1. package/dist/cjs/app-router/client/TernSecureProvider.js +17 -2
  2. package/dist/cjs/app-router/client/TernSecureProvider.js.map +1 -1
  3. package/dist/cjs/app-router/client/actions.js +49 -49
  4. package/dist/cjs/app-router/client/actions.js.map +1 -1
  5. package/dist/cjs/app-router/route-handler/internal-route.js +17 -2
  6. package/dist/cjs/app-router/route-handler/internal-route.js.map +1 -1
  7. package/dist/cjs/boundary/TernSecureClientProvider.js +163 -40
  8. package/dist/cjs/boundary/TernSecureClientProvider.js.map +1 -1
  9. package/dist/cjs/boundary/TernSecureCtx.js.map +1 -1
  10. package/dist/cjs/boundary/hooks/useAuth.js +7 -8
  11. package/dist/cjs/boundary/hooks/useAuth.js.map +1 -1
  12. package/dist/cjs/components/sign-in.js +136 -45
  13. package/dist/cjs/components/sign-in.js.map +1 -1
  14. package/dist/cjs/components/sign-out-button.js +10 -1
  15. package/dist/cjs/components/sign-out-button.js.map +1 -1
  16. package/dist/cjs/components/sign-out.js +12 -3
  17. package/dist/cjs/components/sign-out.js.map +1 -1
  18. package/dist/cjs/components/sign-up.js +10 -5
  19. package/dist/cjs/components/sign-up.js.map +1 -1
  20. package/dist/cjs/errors.js +232 -5
  21. package/dist/cjs/errors.js.map +1 -1
  22. package/dist/cjs/index.js +0 -3
  23. package/dist/cjs/index.js.map +1 -1
  24. package/dist/cjs/types.js +14 -0
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/utils/construct.js +50 -18
  27. package/dist/cjs/utils/construct.js.map +1 -1
  28. package/dist/cjs/utils/redirect.js +57 -0
  29. package/dist/cjs/utils/redirect.js.map +1 -0
  30. package/dist/esm/app-router/client/TernSecureProvider.js +17 -2
  31. package/dist/esm/app-router/client/TernSecureProvider.js.map +1 -1
  32. package/dist/esm/app-router/client/actions.js +59 -51
  33. package/dist/esm/app-router/client/actions.js.map +1 -1
  34. package/dist/esm/app-router/route-handler/internal-route.js +13 -1
  35. package/dist/esm/app-router/route-handler/internal-route.js.map +1 -1
  36. package/dist/esm/boundary/TernSecureClientProvider.js +164 -41
  37. package/dist/esm/boundary/TernSecureClientProvider.js.map +1 -1
  38. package/dist/esm/boundary/TernSecureCtx.js.map +1 -1
  39. package/dist/esm/boundary/hooks/useAuth.js +7 -8
  40. package/dist/esm/boundary/hooks/useAuth.js.map +1 -1
  41. package/dist/esm/components/sign-in.js +137 -46
  42. package/dist/esm/components/sign-in.js.map +1 -1
  43. package/dist/esm/components/sign-out-button.js +11 -2
  44. package/dist/esm/components/sign-out-button.js.map +1 -1
  45. package/dist/esm/components/sign-out.js +13 -4
  46. package/dist/esm/components/sign-out.js.map +1 -1
  47. package/dist/esm/components/sign-up.js +10 -5
  48. package/dist/esm/components/sign-up.js.map +1 -1
  49. package/dist/esm/errors.js +228 -4
  50. package/dist/esm/errors.js.map +1 -1
  51. package/dist/esm/index.js +0 -2
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/types.js +6 -0
  54. package/dist/esm/types.js.map +1 -1
  55. package/dist/esm/utils/construct.js +46 -17
  56. package/dist/esm/utils/construct.js.map +1 -1
  57. package/dist/esm/utils/redirect.js +32 -0
  58. package/dist/esm/utils/redirect.js.map +1 -0
  59. package/dist/types/app-router/client/TernSecureProvider.d.ts +14 -3
  60. package/dist/types/app-router/client/TernSecureProvider.d.ts.map +1 -1
  61. package/dist/types/app-router/client/actions.d.ts +23 -21
  62. package/dist/types/app-router/client/actions.d.ts.map +1 -1
  63. package/dist/types/app-router/route-handler/internal-route.d.ts +3 -0
  64. package/dist/types/app-router/route-handler/internal-route.d.ts.map +1 -1
  65. package/dist/types/boundary/TernSecureClientProvider.d.ts +17 -1
  66. package/dist/types/boundary/TernSecureClientProvider.d.ts.map +1 -1
  67. package/dist/types/boundary/TernSecureCtx.d.ts +3 -1
  68. package/dist/types/boundary/TernSecureCtx.d.ts.map +1 -1
  69. package/dist/types/boundary/hooks/useAuth.d.ts +4 -1
  70. package/dist/types/boundary/hooks/useAuth.d.ts.map +1 -1
  71. package/dist/types/components/sign-in.d.ts +1 -2
  72. package/dist/types/components/sign-in.d.ts.map +1 -1
  73. package/dist/types/components/sign-out-button.d.ts +2 -1
  74. package/dist/types/components/sign-out-button.d.ts.map +1 -1
  75. package/dist/types/components/sign-out.d.ts +2 -1
  76. package/dist/types/components/sign-out.d.ts.map +1 -1
  77. package/dist/types/components/sign-up.d.ts.map +1 -1
  78. package/dist/types/components/ui/alert.d.ts +1 -1
  79. package/dist/types/components/ui/button.d.ts +1 -1
  80. package/dist/types/errors.d.ts +36 -2
  81. package/dist/types/errors.d.ts.map +1 -1
  82. package/dist/types/index.d.ts +0 -1
  83. package/dist/types/index.d.ts.map +1 -1
  84. package/dist/types/types.d.ts +35 -0
  85. package/dist/types/types.d.ts.map +1 -1
  86. package/dist/types/utils/construct.d.ts +20 -4
  87. package/dist/types/utils/construct.d.ts.map +1 -1
  88. package/dist/types/utils/redirect.d.ts +9 -0
  89. package/dist/types/utils/redirect.d.ts.map +1 -0
  90. package/package.json +6 -6
  91. package/dist/cjs/boundary/hooks/useUser.js +0 -44
  92. package/dist/cjs/boundary/hooks/useUser.js.map +0 -1
  93. package/dist/esm/boundary/hooks/useUser.js +0 -20
  94. package/dist/esm/boundary/hooks/useUser.js.map +0 -1
  95. package/dist/types/boundary/hooks/useUser.d.ts +0 -7
  96. package/dist/types/boundary/hooks/useUser.d.ts.map +0 -1
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var redirect_exports = {};
20
+ __export(redirect_exports, {
21
+ getCurrentPath: () => getCurrentPath,
22
+ validateRedirectUrl: () => validateRedirectUrl
23
+ });
24
+ module.exports = __toCommonJS(redirect_exports);
25
+ var import_headers = require("next/headers");
26
+ async function validateRedirectUrl(url) {
27
+ if (!url) return "/";
28
+ try {
29
+ if (url.startsWith("/")) {
30
+ const validPaths = ["/"];
31
+ return validPaths.includes(url) ? url : "/";
32
+ }
33
+ const headersList = await (0, import_headers.headers)();
34
+ const currentHost = headersList.get("host");
35
+ const urlObj = new URL(url);
36
+ if (urlObj.host === currentHost) {
37
+ return urlObj.pathname;
38
+ }
39
+ } catch {
40
+ }
41
+ return "/";
42
+ }
43
+ async function getCurrentPath() {
44
+ try {
45
+ const headersList = await (0, import_headers.headers)();
46
+ const pathname = headersList.get("x-pathname") || "/";
47
+ return pathname;
48
+ } catch {
49
+ return "/";
50
+ }
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ getCurrentPath,
55
+ validateRedirectUrl
56
+ });
57
+ //# sourceMappingURL=redirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/redirect.ts"],"sourcesContent":["import { headers } from \"next/headers\"\n\n/**\n * Validates and sanitizes redirect URLs\n */\nexport async function validateRedirectUrl(url: string | null): Promise<string> {\n if (!url) return \"/\"\n\n try {\n // Check if it's a relative path\n if (url.startsWith(\"/\")) {\n // Basic validation to ensure the path exists in your app\n // Add more paths as needed\n const validPaths = [\"/\"]\n return validPaths.includes(url) ? url : \"/\"\n }\n\n // If it's an absolute URL, ensure it's from your domain\n const headersList = await headers()\n const currentHost = headersList.get(\"host\")\n const urlObj = new URL(url)\n if (urlObj.host === currentHost) {\n return urlObj.pathname\n }\n } catch {\n // Invalid URL format\n }\n\n return \"/\"\n}\n\n/**\n * Gets the current path for redirect purposes\n */\nexport async function getCurrentPath(): Promise<string> {\n try {\n const headersList = await headers()\n const pathname = headersList.get(\"x-pathname\") || \"/\"\n return pathname\n } catch {\n return \"/\"\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAKxB,eAAsB,oBAAoB,KAAqC;AAC7E,MAAI,CAAC,IAAK,QAAO;AAEjB,MAAI;AAEF,QAAI,IAAI,WAAW,GAAG,GAAG;AAGvB,YAAM,aAAa,CAAC,GAAG;AACvB,aAAO,WAAW,SAAS,GAAG,IAAI,MAAM;AAAA,IAC1C;AAGC,UAAM,cAAc,UAAM,wBAAQ;AACnC,UAAM,cAAc,YAAY,IAAI,MAAM;AAC1C,UAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,QAAI,OAAO,SAAS,aAAa;AAC/B,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;AAKA,eAAsB,iBAAkC;AACtD,MAAI;AACF,UAAM,cAAc,UAAM,wBAAQ;AAClC,UAAM,WAAW,YAAY,IAAI,YAAY,KAAK;AAClD,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,7 +1,22 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { TernSecureClientProvider } from "../../boundary/TernSecureClientProvider";
3
- async function TernSecureProvider({ children }) {
4
- return /* @__PURE__ */ jsx(TernSecureClientProvider, { children });
3
+ async function TernSecureProvider({
4
+ children,
5
+ requiresVerification = true,
6
+ loginPath,
7
+ signUpPath,
8
+ loadingComponent
9
+ }) {
10
+ return /* @__PURE__ */ jsx(
11
+ TernSecureClientProvider,
12
+ {
13
+ requiresVerification,
14
+ loginPath,
15
+ signUpPath,
16
+ loadingComponent,
17
+ children
18
+ }
19
+ );
5
20
  }
6
21
  export {
7
22
  TernSecureProvider
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/app-router/client/TernSecureProvider.tsx"],"sourcesContent":["import React from \"react\"\nimport { TernSecureClientProvider } from \"../../boundary/TernSecureClientProvider\"\n\n\n// Loading fallback component\n/*function TernSecureLoadingFallback() {\n return (\n <div>\n <span className=\"sr-only\">Loading...</span>\n </div>\n )\n}*/\n/**\n * Root Provider for TernSecure\n * Use this in your Next.js App Router root layout\n * Automatically handles client/server boundary and authentication state\n * \n * @example\n * /// app/layout.tsx\n * import { TernSecureProvider } from '@tern/secure'\n * \n * export default function RootLayout({ children }) {\n * return (\n * <html>\n * <body>\n * <TernSecureProvider>\n * {children}\n * </TernSecureProvider>\n * </body>\n * </html>\n * )\n * }\n */\nexport async function TernSecureProvider({ children }: { children: React.ReactNode }) {\n return (\n <TernSecureClientProvider>\n {children}\n </TernSecureClientProvider>\n )\n}"],"mappings":"AAmCI;AAlCJ,SAAS,gCAAgC;AAgCzC,eAAsB,mBAAmB,EAAE,SAAS,GAAkC;AACpF,SACE,oBAAC,4BACI,UACL;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/app-router/client/TernSecureProvider.tsx"],"sourcesContent":["import React from \"react\"\nimport { TernSecureClientProvider } from \"../../boundary/TernSecureClientProvider\"\n\n\n/**\n * Configuration options for TernSecure authentication\n */\nexport interface TernSecureConfig {\n /** Whether email verification is required (defaults to true) */\n requiresVerification?: boolean\n /** Custom path for login page (defaults to /sign-in) */\n loginPath?: string\n /** Custom path for signup page (defaults to /sign-up) */\n signUpPath?: string\n /** Custom loading component */\n loadingComponent?: React.ReactNode\n}\n\n// Loading fallback component\n/*function TernSecureLoadingFallback() {\n return (\n <div>\n <span className=\"sr-only\">Loading...</span>\n </div>\n )\n}*/\n/**\n * Root Provider for TernSecure\n * Use this in your Next.js App Router root layout\n * Automatically handles client/server boundary and authentication state\n * \n * @example\n * /// app/layout.tsx\n * import { TernSecureProvider } from '@tern/secure'\n * \n * export default function RootLayout({ children }) {\n * return (\n * <html>\n * <body>\n * <TernSecureProvider>\n * {children}\n * </TernSecureProvider>\n * </body>\n * </html>\n * )\n * }\n */\nexport async function TernSecureProvider({ \n children,\n requiresVerification = true,\n loginPath,\n signUpPath,\n loadingComponent,\n }: React.PropsWithChildren<TernSecureConfig>) {\n return (\n <TernSecureClientProvider\n requiresVerification={requiresVerification}\n loginPath={loginPath}\n signUpPath={signUpPath}\n loadingComponent={loadingComponent}\n >\n {children}\n </TernSecureClientProvider>\n )\n}"],"mappings":"AAuDI;AAtDJ,SAAS,gCAAgC;AA8CzC,eAAsB,mBAAmB;AAAA,EACvC;AAAA,EACA,uBAAuB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACD,GAA8C;AAC7C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEG;AAAA;AAAA,EACL;AAEJ;","names":[]}
@@ -1,6 +1,14 @@
1
1
  import { TernSecureAuth } from "../../utils/client-init";
2
- import { signInWithEmailAndPassword, signInWithRedirect, getRedirectResult, GoogleAuthProvider, OAuthProvider, createUserWithEmailAndPassword, sendEmailVerification } from "firebase/auth";
3
- import { ERRORS } from "../../errors";
2
+ import {
3
+ signInWithEmailAndPassword,
4
+ signInWithRedirect,
5
+ getRedirectResult,
6
+ GoogleAuthProvider,
7
+ OAuthProvider,
8
+ createUserWithEmailAndPassword,
9
+ sendEmailVerification
10
+ } from "firebase/auth";
11
+ import { handleFirebaseAuthError } from "../../errors";
4
12
  async function createUser(email, password) {
5
13
  const auth = TernSecureAuth();
6
14
  try {
@@ -10,27 +18,19 @@ async function createUser(email, password) {
10
18
  };
11
19
  const userCredential = await createUserWithEmailAndPassword(auth, email, password);
12
20
  await sendEmailVerification(userCredential.user, actionCodeSettings);
13
- return { success: true, message: "Account created successfully.", user: userCredential.user };
21
+ return {
22
+ success: true,
23
+ message: "Account created successfully. Please check your email for verification",
24
+ user: userCredential.user
25
+ };
14
26
  } catch (error) {
15
- if (error instanceof Error) {
16
- switch (error.message) {
17
- case "auth/too-many-requests":
18
- throw new Error("Too many attempts. Please try again later.");
19
- case "auth/network-request-failed":
20
- throw new Error("Network disconnected. Please try again later.");
21
- case "auth/email-already-in-use":
22
- throw new Error("Email is already registered.");
23
- case "auth/invalid-email":
24
- throw new Error("Invalid email address.");
25
- case "auth/operation-not-allowed":
26
- throw new Error("Email/password accounts are not enabled.");
27
- case "auth/weak-password":
28
- throw new Error("Password is too weak.");
29
- default:
30
- throw new Error(error.message);
31
- }
32
- }
33
- throw new Error("Failed to create account");
27
+ const authError = handleFirebaseAuthError(error);
28
+ return {
29
+ success: false,
30
+ message: authError.message,
31
+ error: authError.code,
32
+ user: null
33
+ };
34
34
  }
35
35
  }
36
36
  async function signInWithEmail(email, password) {
@@ -41,12 +41,17 @@ async function signInWithEmail(email, password) {
41
41
  return {
42
42
  success: true,
43
43
  message: "Authentication successful",
44
- user: UserCredential.user,
45
- error: !user.emailVerified ? ERRORS.REQUIRES_VERIFICATION : void 0
44
+ user,
45
+ error: !user.emailVerified ? "REQUIRES_VERIFICATION" : "AUTHENTICATED"
46
46
  };
47
47
  } catch (error) {
48
- const errorMessage = error instanceof Error ? error.message : "Failed to sign in";
49
- throw new Error(errorMessage);
48
+ const authError = handleFirebaseAuthError(error);
49
+ return {
50
+ success: false,
51
+ message: authError.message,
52
+ error: authError.code,
53
+ user: null
54
+ };
50
55
  }
51
56
  }
52
57
  async function signInWithRedirectGoogle() {
@@ -60,8 +65,13 @@ async function signInWithRedirectGoogle() {
60
65
  await signInWithRedirect(auth, provider);
61
66
  return { success: true, message: "Redirect initiated" };
62
67
  } catch (error) {
63
- console.error("Error during Google sign-in:", error);
64
- return { success: false, error: "Failed to sign in with Google" };
68
+ const authError = handleFirebaseAuthError(error);
69
+ return {
70
+ success: false,
71
+ message: authError.message,
72
+ error: authError.code,
73
+ user: null
74
+ };
65
75
  }
66
76
  }
67
77
  async function signInWithMicrosoft() {
@@ -74,8 +84,13 @@ async function signInWithMicrosoft() {
74
84
  await signInWithRedirect(auth, provider);
75
85
  return { success: true, message: "Redirect initiated" };
76
86
  } catch (error) {
77
- console.error("Error during Google sign-in:", error);
78
- return { success: false, error: "Failed to sign in with Google" };
87
+ const authError = handleFirebaseAuthError(error);
88
+ return {
89
+ success: false,
90
+ message: authError.message,
91
+ error: authError.code,
92
+ user: null
93
+ };
79
94
  }
80
95
  }
81
96
  async function handleAuthRedirectResult() {
@@ -89,8 +104,13 @@ async function handleAuthRedirectResult() {
89
104
  return { success: false, error: "No redirect result" };
90
105
  }
91
106
  } catch (error) {
92
- console.error("Error handling auth redirect result:", error);
93
- return { success: false, error: error.message || "Failed to handle auth redirect", code: error.code };
107
+ const authError = handleFirebaseAuthError(error);
108
+ return {
109
+ success: false,
110
+ message: authError.message,
111
+ error: authError.code,
112
+ user: null
113
+ };
94
114
  }
95
115
  }
96
116
  async function resendEmailVerification() {
@@ -119,25 +139,13 @@ async function resendEmailVerification() {
119
139
  isVerified: false
120
140
  };
121
141
  } catch (error) {
122
- if (error instanceof Error) {
123
- switch (error.message) {
124
- case "auth/too-many-requests":
125
- throw new Error("Too many attempts. Please try again later.");
126
- case "auth/network-request-failed":
127
- throw new Error("Network disconnected. Please try again later.");
128
- case "auth/email-already-in-use":
129
- throw new Error("Email is already registered.");
130
- case "auth/invalid-email":
131
- throw new Error("Invalid email address.");
132
- case "auth/operation-not-allowed":
133
- throw new Error("Email/password accounts are not enabled.");
134
- case "auth/weak-password":
135
- throw new Error("Password is too weak.");
136
- default:
137
- throw new Error(error.message);
138
- }
139
- }
140
- throw new Error("Failed to resend verification email.");
142
+ const authError = handleFirebaseAuthError(error);
143
+ return {
144
+ success: false,
145
+ message: authError.message,
146
+ error: authError.code,
147
+ user: null
148
+ };
141
149
  }
142
150
  }
143
151
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/app-router/client/actions.ts"],"sourcesContent":["import { TernSecureAuth } from '../../utils/client-init'\nimport { signInWithEmailAndPassword, signInWithRedirect, getRedirectResult, GoogleAuthProvider, OAuthProvider, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth'\nimport { ERRORS } from '../../errors'\n\nexport interface SignInResponse {\n success: boolean;\n message?: string;\n error?: typeof ERRORS[keyof typeof ERRORS];\n user?: any;\n}\n\nexport async function createUser(email: string, password: string) {\n const auth = TernSecureAuth()\n try {\n \n const actionCodeSettings = {\n url: `${window.location.origin}/sign-in`,\n handleCodeInApp: true\n };\n\n const userCredential = await createUserWithEmailAndPassword(auth, email, password);\n\n await sendEmailVerification(userCredential.user, actionCodeSettings)\n \n return { success: true, message: 'Account created successfully.', user: userCredential.user };\n\n } catch (error) {\n // Handle specific Firebase auth errors\n if (error instanceof Error) {\n switch (error.message) {\n case 'auth/too-many-requests':\n throw new Error('Too many attempts. Please try again later.');\n case 'auth/network-request-failed':\n throw new Error('Network disconnected. Please try again later.');\n case 'auth/email-already-in-use':\n throw new Error('Email is already registered.');\n case 'auth/invalid-email':\n throw new Error('Invalid email address.');\n case 'auth/operation-not-allowed':\n throw new Error('Email/password accounts are not enabled.');\n case 'auth/weak-password':\n throw new Error('Password is too weak.');\n default:\n throw new Error(error.message);\n }\n }\n throw new Error('Failed to create account');\n }\n}\n\n\nexport async function signInWithEmail(email: string, password: string): Promise<SignInResponse> {\n const auth = TernSecureAuth()\n try {\n const UserCredential = await signInWithEmailAndPassword(auth, email, password)\n const user = UserCredential.user\n return { \n success: true, \n message: 'Authentication successful',\n user: UserCredential.user,\n error: !user.emailVerified ? ERRORS.REQUIRES_VERIFICATION : undefined\n };\n \n} catch (error){\n const errorMessage = error instanceof Error ? error.message : 'Failed to sign in';\n throw new Error(errorMessage);\n}\n} \n\nexport async function signInWithRedirectGoogle() {\n const auth = TernSecureAuth()\n const provider = new GoogleAuthProvider()\n provider.setCustomParameters({\n login_hint: 'user@example.com',\n prompt: 'select_account'\n })\n\n try {\n await signInWithRedirect(auth, provider)\n return { success: true, message: 'Redirect initiated' }\n } catch (error) {\n console.error('Error during Google sign-in:', error)\n return { success: false, error: 'Failed to sign in with Google' }\n }\n}\n\n\nexport async function signInWithMicrosoft() {\n const auth = TernSecureAuth()\n const provider = new OAuthProvider('microsoft.com')\n provider.setCustomParameters({\n prompt: 'consent'\n })\n\n try {\n await signInWithRedirect(auth, provider)\n return { success: true, message: 'Redirect initiated' }\n } catch (error) {\n console.error('Error during Google sign-in:', error)\n return { success: false, error: 'Failed to sign in with Google' }\n }\n}\n\n\nexport async function handleAuthRedirectResult() {\n const auth = TernSecureAuth()\n try {\n const result = await getRedirectResult(auth)\n if (result) {\n const user = result.user\n return { success: true, user }\n } else {\n return { success: false, error: 'No redirect result' }\n }\n } catch (error: any) {\n console.error('Error handling auth redirect result:', error)\n return { success: false, error: error.message || 'Failed to handle auth redirect', code: error.code }\n }\n}\n\n\nexport async function resendEmailVerification() {\n const auth = TernSecureAuth()\n try {\n const user = auth.currentUser;\n if (!user) {\n throw new Error('No user found. Please try signing up again.');\n }\n\n await user.reload();\n\n if (user.emailVerified) {\n return { \n success: true, \n message: 'Email is already verified. You can sign in.',\n isVerified: true \n };\n }\n\n const actionCodeSettings = {\n url: `${window.location.origin}/sign-in`,\n handleCodeInApp: true,\n };\n\n await sendEmailVerification(user, actionCodeSettings);\n return { \n success: true, \n message: 'Verification email sent successfully.',\n isVerified: false\n };\n } catch (error) {\n if (error instanceof Error) {\n switch (error.message) {\n case 'auth/too-many-requests':\n throw new Error('Too many attempts. Please try again later.');\n case 'auth/network-request-failed':\n throw new Error('Network disconnected. Please try again later.');\n case 'auth/email-already-in-use':\n throw new Error('Email is already registered.');\n case 'auth/invalid-email':\n throw new Error('Invalid email address.');\n case 'auth/operation-not-allowed':\n throw new Error('Email/password accounts are not enabled.');\n case 'auth/weak-password':\n throw new Error('Password is too weak.');\n default:\n throw new Error(error.message);\n }\n }\n throw new Error('Failed to resend verification email.');\n }\n}"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B,oBAAoB,mBAAmB,oBAAoB,eAAe,gCAAgC,6BAA6B;AAC5K,SAAS,cAAc;AASvB,eAAsB,WAAW,OAAe,UAAkB;AAChE,QAAM,OAAO,eAAe;AAC5B,MAAI;AAEF,UAAM,qBAAqB;AAAA,MACzB,KAAK,GAAG,OAAO,SAAS,MAAM;AAAA,MAC9B,iBAAiB;AAAA,IACnB;AAEA,UAAM,iBAAiB,MAAM,+BAA+B,MAAM,OAAO,QAAQ;AAEjF,UAAM,sBAAsB,eAAe,MAAM,kBAAkB;AAEnE,WAAO,EAAE,SAAS,MAAM,SAAS,iCAAiC,MAAM,eAAe,KAAK;AAAA,EAE9F,SAAS,OAAO;AAEd,QAAI,iBAAiB,OAAO;AAC1B,cAAQ,MAAM,SAAS;AAAA,QACrB,KAAK;AACH,gBAAM,IAAI,MAAM,4CAA4C;AAAA,QAC9D,KAAK;AACD,gBAAM,IAAI,MAAM,+CAA+C;AAAA,QACnE,KAAK;AACH,gBAAM,IAAI,MAAM,8BAA8B;AAAA,QAChD,KAAK;AACH,gBAAM,IAAI,MAAM,wBAAwB;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,MAAM,0CAA0C;AAAA,QAC5D,KAAK;AACH,gBAAM,IAAI,MAAM,uBAAuB;AAAA,QACzC;AACE,gBAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MACjC;AAAA,IACF;AACA,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AACF;AAGA,eAAsB,gBAAgB,OAAe,UAA2C;AAC9F,QAAM,OAAO,eAAe;AAC5B,MAAI;AACJ,UAAM,iBAAiB,MAAM,2BAA2B,MAAM,OAAO,QAAQ;AAC7E,UAAM,OAAO,eAAe;AAC5B,WAAO;AAAA,MACH,SAAS;AAAA,MACT,SAAS;AAAA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O,EAAE,SAAS,OAAO,OAAO,MAAM,WAAW,kCAAkC,MAAM,MAAM,KAAK;AAAA,EACtG;AACF;AAGA,eAAsB,0BAA0B;AAC9C,QAAM,OAAO,eAAe;AAC5B,MAAI;AACF,UAAM,OAAO,KAAK;AAClB,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,UAAM,KAAK,OAAO;AAElB,QAAI,KAAK,eAAe;AACtB,aAAO;AAAA,QACL,SAAS;AAAA,QACT,SAAS;AAAA,QACT,YAAY;AAAA,MACd;AAAA,IACF;AAEA,UAAM,qBAAqB;AAAA,MACzB,KAAK,GAAG,OAAO,SAAS,MAAM;AAAA,MAC9B,iBAAiB;AAAA,IACnB;AAEA,UAAM,sBAAsB,MAAM,kBAAkB;AACpD,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS;AAAA,MACT,YAAY;AAAA,IACb;AAAA,EACD,SAAS,OAAO;AACd,QAAI,iBAAiB,OAAO;AAC1B,cAAQ,MAAM,SAAS;AAAA,QACrB,KAAK;AACH,gBAAM,IAAI,MAAM,4CAA4C;AAAA,QAC9D,KAAK;AACD,gBAAM,IAAI,MAAM,+CAA+C;AAAA,QACnE,KAAK;AACH,gBAAM,IAAI,MAAM,8BAA8B;AAAA,QAChD,KAAK;AACH,gBAAM,IAAI,MAAM,wBAAwB;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,MAAM,0CAA0C;AAAA,QAC5D,KAAK;AACH,gBAAM,IAAI,MAAM,uBAAuB;AAAA,QACzC;AACE,gBAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MACjC;AAAA,IACF;AACA,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/app-router/client/actions.ts"],"sourcesContent":["import { TernSecureAuth } from '../../utils/client-init'\nimport { \n signInWithEmailAndPassword, \n signInWithRedirect, \n getRedirectResult, \n GoogleAuthProvider, \n OAuthProvider, \n createUserWithEmailAndPassword, \n sendEmailVerification } from 'firebase/auth'\nimport type { SignInResponse } from '../../types'\nimport { handleFirebaseAuthError } from '../../errors'\n\n\nexport async function createUser(email: string, password: string): Promise<SignInResponse> {\n const auth = TernSecureAuth()\n try {\n \n const actionCodeSettings = {\n url: `${window.location.origin}/sign-in`,\n handleCodeInApp: true\n };\n\n const userCredential = await createUserWithEmailAndPassword(auth, email, password);\n\n await sendEmailVerification(userCredential.user, actionCodeSettings)\n \n return { \n success: true, \n message: 'Account created successfully. Please check your email for verification', \n user: userCredential.user \n };\n\n } catch (error) {\n const authError = handleFirebaseAuthError(error)\n return { \n success: false, \n message: authError.message, \n error: authError.code,\n user: null\n }\n }\n}\n\n\nexport async function signInWithEmail(email: string, password: string): Promise<SignInResponse> {\n const auth = TernSecureAuth()\n try {\n const UserCredential = await signInWithEmailAndPassword(auth, email, password)\n const user = UserCredential.user\n \n return { \n success: true, \n message: 'Authentication successful',\n user: user,\n error: !user.emailVerified ? 'REQUIRES_VERIFICATION' : 'AUTHENTICATED'\n };\n\n} catch (error){\n const authError = handleFirebaseAuthError(error)\n return { \n success: false,\n message: authError.message,\n error: authError.code,\n user: null\n }\n}\n}\n\nexport async function signInWithRedirectGoogle() {\n const auth = TernSecureAuth()\n const provider = new GoogleAuthProvider()\n provider.setCustomParameters({\n login_hint: 'user@example.com',\n prompt: 'select_account'\n })\n\n try {\n await signInWithRedirect(auth, provider)\n return { success: true, message: 'Redirect initiated' }\n } catch (error) {\n const authError = handleFirebaseAuthError(error)\n return {\n success: false,\n message: authError.message,\n error: authError.code,\n user: null\n }\n }\n}\n\n\nexport async function signInWithMicrosoft() {\n const auth = TernSecureAuth()\n const provider = new OAuthProvider('microsoft.com')\n provider.setCustomParameters({\n prompt: 'consent'\n })\n\n try {\n await signInWithRedirect(auth, provider)\n return { success: true, message: 'Redirect initiated' }\n } catch (error) {\n const authError = handleFirebaseAuthError(error)\n return {\n success: false, \n message: authError.message,\n error: authError.code,\n user: null\n }\n }\n}\n\n\nexport async function handleAuthRedirectResult() {\n const auth = TernSecureAuth()\n try {\n const result = await getRedirectResult(auth)\n if (result) {\n const user = result.user\n return { success: true, user }\n } else {\n return { success: false, error: 'No redirect result' }\n }\n } catch (error: any) {\n const authError = handleFirebaseAuthError(error)\n return {\n success: false,\n message: authError.message,\n error: authError.code,\n user: null\n }\n }\n}\n\n\nexport async function resendEmailVerification() {\n const auth = TernSecureAuth()\n try {\n const user = auth.currentUser;\n if (!user) {\n throw new Error('No user found. Please try signing up again.');\n }\n\n await user.reload();\n\n if (user.emailVerified) {\n return { \n success: true, \n message: 'Email is already verified. You can sign in.',\n isVerified: true \n };\n }\n\n const actionCodeSettings = {\n url: `${window.location.origin}/sign-in`,\n handleCodeInApp: true,\n };\n\n await sendEmailVerification(user, actionCodeSettings);\n return { \n success: true, \n message: 'Verification email sent successfully.',\n isVerified: false\n };\n } catch (error) {\n const authError = handleFirebaseAuthError(error)\n return {\n success: false,\n message: authError.message,\n error: authError.code,\n user: null\n }\n }\n}"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAA6B;AAE/B,SAAS,+BAA+B;AAGxC,eAAsB,WAAW,OAAe,UAA2C;AACzF,QAAM,OAAO,eAAe;AAC5B,MAAI;AAEF,UAAM,qBAAqB;AAAA,MACzB,KAAK,GAAG,OAAO,SAAS,MAAM;AAAA,MAC9B,iBAAiB;AAAA,IACnB;AAEA,UAAM,iBAAiB,MAAM,+BAA+B,MAAM,OAAO,QAAQ;AAEjF,UAAM,sBAAsB,eAAe,MAAM,kBAAkB;AAEnE,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS;AAAA,MACT,MAAM,eAAe;AAAA,IACvB;AAAA,EAEF,SAAS,OAAO;AACd,UAAM,YAAY,wBAAwB,KAAK;AAC/C,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAA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,15 @@ const internalRoutes = {
9
9
  component: Verify
10
10
  }
11
11
  };
12
+ function isInternalRoute(pathname) {
13
+ return Object.values(internalRoutes).some((route) => route.pattern.test(pathname));
14
+ }
15
+ function isAuthRoute(pathname) {
16
+ return pathname.startsWith("/sign-in") || pathname.startsWith("/sign-up");
17
+ }
18
+ function isBaseAuthRoute(pathname) {
19
+ return pathname === "/sign-in" || pathname === "/sign-up";
20
+ }
12
21
  function handleInternalRoute(pathname) {
13
22
  for (const [key, route] of Object.entries(internalRoutes)) {
14
23
  if (route.pattern.test(pathname)) {
@@ -19,6 +28,9 @@ function handleInternalRoute(pathname) {
19
28
  }
20
29
  export {
21
30
  handleInternalRoute,
22
- internalRoutes
31
+ internalRoutes,
32
+ isAuthRoute,
33
+ isBaseAuthRoute,
34
+ isInternalRoute
23
35
  };
24
36
  //# sourceMappingURL=internal-route.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/app-router/route-handler/internal-route.tsx"],"sourcesContent":["import { Verify } from \"../../components/verify\"\n\n// Internal route mapping\nexport const internalRoutes = {\n signUpVerify: {\n pattern: /^\\/sign-up\\/verify$/,\n component: Verify,\n },\n signInVerify: {\n pattern: /^\\/sign-in\\/verify$/,\n component: Verify,\n },\n}\n\n// Internal route handler\nexport function handleInternalRoute(pathname: string) {\n for (const [key, route] of Object.entries(internalRoutes)) {\n if (route.pattern.test(pathname)) {\n return route.component\n }\n }\n return null\n}\n\n"],"mappings":"AAAA,SAAS,cAAc;AAGhB,MAAM,iBAAiB;AAAA,EAC5B,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AAGO,SAAS,oBAAoB,UAAkB;AACpD,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,cAAc,GAAG;AACzD,QAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAChC,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/app-router/route-handler/internal-route.tsx"],"sourcesContent":["import { Verify } from \"../../components/verify\"\n\n// Internal route mapping\nexport const internalRoutes = {\n signUpVerify: {\n pattern: /^\\/sign-up\\/verify$/,\n component: Verify,\n },\n signInVerify: {\n pattern: /^\\/sign-in\\/verify$/,\n component: Verify,\n },\n}\n\n// Check if path is an internal route\nexport function isInternalRoute(pathname: string): boolean {\n return Object.values(internalRoutes).some((route) => route.pattern.test(pathname))\n}\n\n// Check if path is within auth routes\nexport function isAuthRoute(pathname: string): boolean {\n return pathname.startsWith(\"/sign-in\") || pathname.startsWith(\"/sign-up\")\n}\n\n// Check if path is exactly the base auth route\nexport function isBaseAuthRoute(pathname: string): boolean {\n return pathname === \"/sign-in\" || pathname === \"/sign-up\"\n}\n\n// Internal route handler\nexport function handleInternalRoute(pathname: string) {\n for (const [key, route] of Object.entries(internalRoutes)) {\n if (route.pattern.test(pathname)) {\n return route.component\n }\n }\n return null\n}"],"mappings":"AAAA,SAAS,cAAc;AAGhB,MAAM,iBAAiB;AAAA,EAC5B,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AAGO,SAAS,gBAAgB,UAA2B;AACzD,SAAO,OAAO,OAAO,cAAc,EAAE,KAAK,CAAC,UAAU,MAAM,QAAQ,KAAK,QAAQ,CAAC;AACnF;AAGO,SAAS,YAAY,UAA2B;AACrD,SAAO,SAAS,WAAW,UAAU,KAAK,SAAS,WAAW,UAAU;AAC1E;AAGO,SAAS,gBAAgB,UAA2B;AACzD,SAAO,aAAa,cAAc,aAAa;AACjD;AAGO,SAAS,oBAAoB,UAAkB;AACpD,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,cAAc,GAAG;AACzD,QAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAChC,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -4,14 +4,20 @@ import { useState, useEffect, useMemo, useCallback } from "react";
4
4
  import { ternSecureAuth } from "../utils/client-init";
5
5
  import { onAuthStateChanged } from "firebase/auth";
6
6
  import { TernSecureCtx } from "./TernSecureCtx";
7
- import { useRouter } from "next/navigation";
7
+ import { useRouter, usePathname } from "next/navigation";
8
+ import { isBaseAuthRoute, isInternalRoute, isAuthRoute } from "../app-router/route-handler/internal-route";
9
+ import { hasRedirectLoop } from "../utils/construct";
8
10
  function TernSecureClientProvider({
9
11
  children,
10
- loginPath = "/sign-in",
11
- loadingComponent
12
+ loginPath = process.env.NEXT_PUBLIC_SIGN_IN_PATH || "/sign-in",
13
+ signUpPath = process.env.NEXT_PUBLIC_SIGN_UP_PATH || "/sign-up",
14
+ loadingComponent,
15
+ requiresVerification
12
16
  }) {
13
17
  const auth = useMemo(() => ternSecureAuth, []);
14
18
  const router = useRouter();
19
+ const pathname = usePathname();
20
+ const [isRedirecting, setIsRedirecting] = useState(false);
15
21
  const [authState, setAuthState] = useState(() => ({
16
22
  userId: null,
17
23
  isLoaded: false,
@@ -20,9 +26,58 @@ function TernSecureClientProvider({
20
26
  isVerified: false,
21
27
  isAuthenticated: false,
22
28
  token: null,
23
- email: null
29
+ email: null,
30
+ status: "loading",
31
+ requiresVerification
24
32
  }));
33
+ const constructUrlWithRedirect = useCallback(
34
+ (loginPath2, currentPath, loginPathParam, signUpPathParam) => {
35
+ const baseUrl = window.location.origin;
36
+ const signInUrl = new URL(loginPath2, baseUrl);
37
+ if (!currentPath.includes(loginPathParam) && !currentPath.includes(signUpPathParam)) {
38
+ signInUrl.searchParams.set("redirect", currentPath);
39
+ }
40
+ return signInUrl.toString();
41
+ },
42
+ []
43
+ );
44
+ const shouldRedirect = useCallback(
45
+ (pathname2, isVerified) => {
46
+ const searchParams = new URLSearchParams(window.location.search);
47
+ if (isBaseAuthRoute(pathname2) && !searchParams.has("redirect")) {
48
+ return false;
49
+ }
50
+ if (isInternalRoute(pathname2)) {
51
+ return false;
52
+ }
53
+ if (isAuthRoute(pathname2) && (!requiresVerification || isVerified)) {
54
+ return false;
55
+ }
56
+ return true;
57
+ },
58
+ [requiresVerification]
59
+ );
60
+ const redirectToLogin = useCallback(
61
+ (currentPath) => {
62
+ const path = currentPath || pathname || "/";
63
+ if (isInternalRoute(path)) {
64
+ return;
65
+ }
66
+ if (hasRedirectLoop(path, loginPath)) {
67
+ return;
68
+ }
69
+ setIsRedirecting(true);
70
+ const loginUrl = constructUrlWithRedirect(loginPath, path, loginPath, signUpPath);
71
+ if (process.env.NODE_ENV === "production") {
72
+ window.location.href = loginUrl;
73
+ } else {
74
+ router.push(loginUrl);
75
+ }
76
+ },
77
+ [router, loginPath, signUpPath, pathname, constructUrlWithRedirect]
78
+ );
25
79
  const handleSignOut = useCallback(async (error) => {
80
+ const currentPath = window.location.pathname;
26
81
  await auth.signOut();
27
82
  setAuthState({
28
83
  isLoaded: true,
@@ -32,56 +87,124 @@ function TernSecureClientProvider({
32
87
  token: null,
33
88
  email: null,
34
89
  isVerified: false,
35
- isAuthenticated: false
90
+ isAuthenticated: false,
91
+ status: "unauthenticated",
92
+ requiresVerification
36
93
  });
37
- router.push(loginPath);
38
- }, [auth, router, loginPath]);
94
+ redirectToLogin(currentPath);
95
+ }, [auth, redirectToLogin, requiresVerification]);
39
96
  const setEmail = useCallback((email) => {
40
97
  setAuthState((prev) => ({
41
98
  ...prev,
42
99
  email
43
100
  }));
44
101
  }, []);
102
+ const getAuthError = useCallback(() => {
103
+ if (authState.error) {
104
+ const error = authState.error;
105
+ return {
106
+ success: false,
107
+ message: error.message,
108
+ error: error.code,
109
+ user: null
110
+ };
111
+ }
112
+ if (authState.requiresVerification && authState.isValid && !authState.isVerified) {
113
+ return {
114
+ success: false,
115
+ message: "Email verification required",
116
+ error: "EMAIL_NOT_VERIFIED",
117
+ user: null
118
+ };
119
+ }
120
+ if (!authState.isAuthenticated && authState.status !== "loading") {
121
+ return {
122
+ success: false,
123
+ message: "User is not authenticated",
124
+ error: "AUTHENTICATED",
125
+ user: null
126
+ };
127
+ }
128
+ return {
129
+ success: true,
130
+ user: ternSecureAuth.currentUser
131
+ };
132
+ }, [
133
+ authState.error,
134
+ authState.isValid,
135
+ authState.isVerified,
136
+ authState.isAuthenticated,
137
+ authState.status,
138
+ authState.requiresVerification
139
+ ]);
45
140
  useEffect(() => {
46
- const unsubscribe = onAuthStateChanged(auth, async (user) => {
47
- if (user) {
48
- const isValid = !!user.uid;
49
- const isVerified = user.emailVerified;
50
- setAuthState({
51
- isLoaded: true,
52
- userId: user.uid,
53
- isValid,
54
- isVerified,
55
- isAuthenticated: isValid && isVerified,
56
- token: user.getIdToken(),
57
- error: null,
58
- email: user.email
59
- });
60
- } else {
61
- setAuthState({
62
- isLoaded: true,
63
- userId: null,
64
- isValid: false,
65
- isVerified: false,
66
- isAuthenticated: false,
67
- token: null,
68
- error: new Error("User is not authenticated"),
69
- email: null
70
- });
71
- if (!window.location.pathname.includes("/sign-up")) {
72
- router.push(loginPath);
141
+ let mounted = true;
142
+ let initialLoad = true;
143
+ const unsubscribe = onAuthStateChanged(
144
+ auth,
145
+ async (user) => {
146
+ if (!mounted) return;
147
+ try {
148
+ if (user) {
149
+ const isValid = !!user.uid;
150
+ const isVerified = user.emailVerified;
151
+ const isAuthenticated = isValid && (!requiresVerification || isVerified);
152
+ setAuthState({
153
+ isLoaded: true,
154
+ userId: user.uid,
155
+ isValid,
156
+ isVerified,
157
+ isAuthenticated: isValid && isVerified,
158
+ token: user.getIdToken(),
159
+ error: null,
160
+ email: user.email,
161
+ status: isAuthenticated ? "authenticated" : "unverified",
162
+ requiresVerification
163
+ });
164
+ if (requiresVerification && !isVerified && shouldRedirect(pathname || "", isVerified)) {
165
+ if (initialLoad || !isRedirecting) {
166
+ redirectToLogin(pathname);
167
+ }
168
+ }
169
+ } else {
170
+ setAuthState({
171
+ isLoaded: true,
172
+ userId: null,
173
+ isValid: false,
174
+ isVerified: false,
175
+ isAuthenticated: false,
176
+ token: null,
177
+ error: null,
178
+ email: null,
179
+ status: "unauthenticated",
180
+ requiresVerification
181
+ });
182
+ if (shouldRedirect(pathname || "", false) && initialLoad) {
183
+ redirectToLogin();
184
+ }
185
+ }
186
+ } catch (error) {
187
+ console.error("Auth state change error:", error);
188
+ if (mounted) {
189
+ handleSignOut(error instanceof Error ? error : new Error("Authentication error occurred"));
190
+ }
191
+ } finally {
192
+ initialLoad = false;
73
193
  }
74
194
  }
75
- }, (error) => {
76
- handleSignOut(error instanceof Error ? error : new Error("Authentication error occurred"));
77
- });
78
- return () => unsubscribe();
79
- }, [auth, handleSignOut, router, loginPath]);
195
+ );
196
+ return () => {
197
+ mounted = false;
198
+ unsubscribe();
199
+ };
200
+ }, [auth, handleSignOut, redirectToLogin, requiresVerification, pathname, isRedirecting, shouldRedirect]);
80
201
  const contextValue = useMemo(() => ({
81
202
  ...authState,
82
203
  signOut: handleSignOut,
83
- setEmail
84
- }), [authState, auth, handleSignOut, setEmail]);
204
+ setEmail,
205
+ getAuthError,
206
+ redirectToLogin
207
+ }), [authState, handleSignOut, setEmail, getAuthError, redirectToLogin]);
85
208
  if (!authState.isLoaded) {
86
209
  return /* @__PURE__ */ jsx(TernSecureCtx.Provider, { value: contextValue, children: loadingComponent || /* @__PURE__ */ jsx("div", { "aria-live": "polite", "aria-busy": "true", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading authentication state..." }) }) });
87
210
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/boundary/TernSecureClientProvider.tsx"],"sourcesContent":["\"use client\"\n\nimport React, { useState, useEffect, useMemo, useCallback } from 'react'\nimport { ternSecureAuth } from '../utils/client-init'\nimport { onAuthStateChanged, User } from \"firebase/auth\"\nimport { TernSecureCtx, TernSecureCtxValue } from './TernSecureCtx'\nimport { type TernSecureState } from '../types'\nimport { useRouter } from 'next/navigation'\n\ninterface TernSecureClientProviderProps {\n children: React.ReactNode;\n onUserChanged?: (user: User | null) => Promise<void>;\n loginPath?: string;\n loadingComponent?: React.ReactNode;\n}\n\nexport function TernSecureClientProvider({ \n children, \n loginPath = '/sign-in',\n loadingComponent\n}: TernSecureClientProviderProps) {\n const auth = useMemo(() => ternSecureAuth, []);\n const router = useRouter();\n const [authState, setAuthState] = useState<TernSecureState>(() => ({\n userId: null,\n isLoaded: false,\n error: null,\n isValid: false,\n isVerified: false,\n isAuthenticated: false,\n token: null,\n email: null,\n }));\n\n const handleSignOut = useCallback(async (error?: Error) => {\n await auth.signOut();\n setAuthState({\n isLoaded: true,\n userId: null,\n error: error || null,\n isValid: false,\n token: null,\n email: null,\n isVerified: false,\n isAuthenticated: false,\n });\n router.push(loginPath);\n }, [auth, router, loginPath]);\n\n const setEmail = useCallback((email: string) => {\n setAuthState((prev) => ({\n ...prev,\n email,\n }))\n }, [])\n\nuseEffect(() => {\n const unsubscribe = onAuthStateChanged(auth, async (user: User | null) => {\n if (user) {\n const isValid = !!user.uid;\n const isVerified = user.emailVerified;\n setAuthState({\n isLoaded: true,\n userId: user.uid,\n isValid,\n isVerified,\n isAuthenticated: isValid && isVerified,\n token: user.getIdToken(),\n error: null,\n email: user.email,\n })\n } else {\n setAuthState({\n isLoaded: true,\n userId: null,\n isValid: false,\n isVerified: false,\n isAuthenticated: false,\n token: null,\n error: new Error('User is not authenticated'),\n email: null,\n })\n if (!window.location.pathname.includes(\"/sign-up\")) {\n router.push(loginPath)\n }\n }\n }, (error) => {\n handleSignOut(error instanceof Error ? error : new Error('Authentication error occurred'));\n })\n \n return () => unsubscribe()\n }, [auth, handleSignOut, router, loginPath])\n\n const contextValue: TernSecureCtxValue = useMemo(() => ({\n ...authState,\n signOut: handleSignOut,\n setEmail\n }), [authState, auth, handleSignOut, setEmail]);\n\n if (!authState.isLoaded) {\n return (\n <TernSecureCtx.Provider value={contextValue}>\n {loadingComponent || (\n <div aria-live=\"polite\" aria-busy=\"true\">\n <span className=\"sr-only\">Loading authentication state...</span>\n </div>\n )}\n </TernSecureCtx.Provider>\n );\n }\n\n return (\n <TernSecureCtx.Provider value={contextValue}>\n {children}\n </TernSecureCtx.Provider>\n )\n}"],"mappings":";AAwGY;AAtGZ,SAAgB,UAAU,WAAW,SAAS,mBAAmB;AACjE,SAAS,sBAAsB;AAC/B,SAAS,0BAAgC;AACzC,SAAS,qBAAyC;AAElD,SAAS,iBAAiB;AASnB,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA,YAAY;AAAA,EACZ;AACF,GAAkC;AAChC,QAAM,OAAO,QAAQ,MAAM,gBAAgB,CAAC,CAAC;AAC7C,QAAM,SAAS,UAAU;AACzB,QAAM,CAAC,WAAW,YAAY,IAAI,SAA0B,OAAO;AAAA,IACjE,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,OAAO;AAAA,IACP,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,OAAO;AAAA,IACP,OAAO;AAAA,EACT,EAAE;AAEF,QAAM,gBAAgB,YAAY,OAAO,UAAkB;AACzD,UAAM,KAAK,QAAQ;AACnB,iBAAa;AAAA,MACX,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,OAAO,SAAS;AAAA,MAChB,SAAS;AAAA,MACT,OAAO;AAAA,MACP,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,iBAAiB;AAAA,IACnB,CAAC;AACD,WAAO,KAAK,SAAS;AAAA,EACvB,GAAG,CAAC,MAAM,QAAQ,SAAS,CAAC;AAE5B,QAAM,WAAW,YAAY,CAAC,UAAkB;AAC9C,iBAAa,CAAC,UAAU;AAAA,MACtB,GAAG;AAAA,MACH;AAAA,IACF,EAAE;AAAA,EACJ,GAAG,CAAC,CAAC;AAEP,YAAU,MAAM;AACZ,UAAM,cAAc,mBAAmB,MAAM,OAAO,SAAsB;AACxE,UAAI,MAAM;AACR,cAAM,UAAU,CAAC,CAAC,KAAK;AACvB,cAAM,aAAa,KAAK;AACxB,qBAAa;AAAA,UACX,UAAU;AAAA,UACV,QAAQ,KAAK;AAAA,UACb;AAAA,UACA;AAAA,UACA,iBAAiB,WAAW;AAAA,UAC5B,OAAO,KAAK,WAAW;AAAA,UACvB,OAAO;AAAA,UACP,OAAO,KAAK;AAAA,QACd,CAAC;AAAA,MACH,OAAO;AACL,qBAAa;AAAA,UACX,UAAU;AAAA,UACV,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,YAAY;AAAA,UACZ,iBAAiB;AAAA,UACjB,OAAO;AAAA,UACP,OAAO,IAAI,MAAM,2BAA2B;AAAA,UAC5C,OAAO;AAAA,QACT,CAAC;AACD,YAAI,CAAC,OAAO,SAAS,SAAS,SAAS,UAAU,GAAG;AAClD,iBAAO,KAAK,SAAS;AAAA,QACvB;AAAA,MACF;AAAA,IACF,GAAG,CAAC,UAAU;AACZ,oBAAc,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,+BAA+B,CAAC;AAAA,IAC3F,CAAC;AAED,WAAO,MAAM,YAAY;AAAA,EAC3B,GAAG,CAAC,MAAM,eAAe,QAAQ,SAAS,CAAC;AAE3C,QAAM,eAAmC,QAAQ,OAAO;AAAA,IACtD,GAAG;AAAA,IACH,SAAS;AAAA,IACT;AAAA,EACF,IAAI,CAAC,WAAW,MAAM,eAAe,QAAQ,CAAC;AAE9C,MAAI,CAAC,UAAU,UAAU;AACvB,WACE,oBAAC,cAAc,UAAd,EAAuB,OAAO,cAC5B,8BACC,oBAAC,SAAI,aAAU,UAAS,aAAU,QAChC,8BAAC,UAAK,WAAU,WAAU,6CAA+B,GAC3D,GAEJ;AAAA,EAEJ;AAEA,SACI,oBAAC,cAAc,UAAd,EAAuB,OAAO,cAC7B,UACF;AAEN;","names":[]}
1
+ {"version":3,"sources":["../../../src/boundary/TernSecureClientProvider.tsx"],"sourcesContent":["\"use client\"\n\nimport React, { useState, useEffect, useMemo, useCallback } from 'react'\nimport { ternSecureAuth } from '../utils/client-init'\nimport { onAuthStateChanged, User } from \"firebase/auth\"\nimport { TernSecureCtx, TernSecureCtxValue } from './TernSecureCtx'\nimport type { TernSecureState, AuthError, SignInResponse } from \"../types\"\nimport type { ERRORS } from '../errors'\nimport { useRouter, usePathname } from 'next/navigation'\nimport { isBaseAuthRoute, isInternalRoute, isAuthRoute} from '../app-router/route-handler/internal-route'\nimport { hasRedirectLoop } from '../utils/construct'\n\n\n\n/**\n * @internal\n * Internal provider props - not meant for direct usage\n */\ninterface TernSecureClientProviderProps {\n children: React.ReactNode\n /** Callback when user state changes */\n onUserChanged?: (user: User | null) => Promise<void>\n /** Login page path */\n loginPath?: string\n /** Signup page path */\n signUpPath?: string\n /** Custom loading component */\n loadingComponent?: React.ReactNode\n /** Whether email verification is required */\n requiresVerification: boolean\n}\n\n/**\n * @internal\n * Internal provider component that handles authentication state\n * This is wrapped by the public TernSecureProvider\n */\n\nexport function TernSecureClientProvider({ \n children, \n loginPath = process.env.NEXT_PUBLIC_SIGN_IN_PATH || '/sign-in',\n signUpPath = process.env.NEXT_PUBLIC_SIGN_UP_PATH || '/sign-up',\n loadingComponent,\n requiresVerification,\n}: TernSecureClientProviderProps) {\n const auth = useMemo(() => ternSecureAuth, []);\n const router = useRouter();\n const pathname = usePathname() // Get current pathname\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const [authState, setAuthState] = useState<TernSecureState>(() => ({\n userId: null,\n isLoaded: false,\n error: null,\n isValid: false,\n isVerified: false,\n isAuthenticated: false,\n token: null,\n email: null,\n status: \"loading\",\n requiresVerification,\n }));\n\n const constructUrlWithRedirect = useCallback(\n (loginPath: string, currentPath: string, loginPathParam: string, signUpPathParam: string): string => {\n const baseUrl = window.location.origin\n const signInUrl = new URL(loginPath, baseUrl)\n\n // Only add redirect if not already on login or signup page\n if (!currentPath.includes(loginPathParam) && !currentPath.includes(signUpPathParam)) {\n signInUrl.searchParams.set(\"redirect\", currentPath)\n }\n return signInUrl.toString()\n },\n [],\n )\n\n\n const shouldRedirect = useCallback(\n (pathname: string, isVerified: boolean) => {\n // Get current search params\n const searchParams = new URLSearchParams(window.location.search)\n\n // Don't redirect if we're on the base sign-in page with no redirect param\n if (isBaseAuthRoute(pathname) && !searchParams.has(\"redirect\")) {\n return false\n }\n\n // Don't redirect if we're on an internal route\n if (isInternalRoute(pathname)) {\n return false\n }\n\n // Don't redirect if we're in auth routes (except when handling verification)\n if (isAuthRoute(pathname) && (!requiresVerification || isVerified)) {\n return false\n }\n\n return true\n },\n [requiresVerification],\n )\n\n const redirectToLogin = useCallback(\n (currentPath?: string) => {\n const path = currentPath || pathname || \"/\"\n\n\n if (isInternalRoute(path)) { // Don't redirect if we're already on an internal route\n return\n }\n\n // Check for redirect loops\n if (hasRedirectLoop(path, loginPath)) {\n return\n }\n\n setIsRedirecting(true)\n\n const loginUrl = constructUrlWithRedirect(loginPath, path, loginPath, signUpPath)\n\n if (process.env.NODE_ENV === \"production\") {\n window.location.href = loginUrl\n } else {\n // Use router.push for development\n router.push(loginUrl)\n }\n }, \n [router, loginPath, signUpPath, pathname, constructUrlWithRedirect]\n)\n\n const handleSignOut = useCallback(async (error?: Error) => {\n const currentPath = window.location.pathname\n await auth.signOut();\n setAuthState({\n isLoaded: true,\n userId: null,\n error: error || null,\n isValid: false,\n token: null,\n email: null,\n isVerified: false,\n isAuthenticated: false,\n status: \"unauthenticated\",\n requiresVerification,\n })\n redirectToLogin(currentPath)\n }, [auth, redirectToLogin, requiresVerification])\n\n const setEmail = useCallback((email: string) => {\n setAuthState((prev) => ({\n ...prev,\n email,\n }))\n }, [])\n\n const getAuthError = useCallback((): SignInResponse => {\n if (authState.error) {\n const error = authState.error as AuthError;\n return {\n success: false,\n message: error.message,\n error: error.code as keyof typeof ERRORS,\n user: null,\n }\n }\n\n if (authState.requiresVerification && authState.isValid && !authState.isVerified) {\n return {\n success: false,\n message: 'Email verification required',\n error: 'EMAIL_NOT_VERIFIED',\n user: null,\n }\n }\n\n if (!authState.isAuthenticated && authState.status !== \"loading\") {\n return {\n success: false,\n message: 'User is not authenticated',\n error: 'AUTHENTICATED',\n user: null,\n }\n }\n\n return {\n success: true,\n user: ternSecureAuth.currentUser,\n }\n }, [\n authState.error,\n authState.isValid,\n authState.isVerified,\n authState.isAuthenticated,\n authState.status,\n authState.requiresVerification,\n ])\n\nuseEffect(() => {\n let mounted = true\n let initialLoad = true\n\n const unsubscribe = onAuthStateChanged(\n auth,\n async (user: User | null) => {\n if (!mounted) return\n try {\n if (user) {\n const isValid = !!user.uid;\n const isVerified = user.emailVerified;\n const isAuthenticated = isValid && (!requiresVerification || isVerified) // Consider user authenticated if verification is not required or if email is verified\n\n setAuthState({\n isLoaded: true,\n userId: user.uid,\n isValid,\n isVerified,\n isAuthenticated: isValid && isVerified,\n token: user.getIdToken(),\n error: null,\n email: user.email,\n status: isAuthenticated ? \"authenticated\" : \"unverified\",\n requiresVerification,\n })\n \n if (requiresVerification && !isVerified && shouldRedirect(pathname || \"\", isVerified)) {\n if(initialLoad || !isRedirecting) {\n redirectToLogin(pathname)\n }\n }\n } else {\n setAuthState({\n isLoaded: true,\n userId: null,\n isValid: false,\n isVerified: false,\n isAuthenticated: false,\n token: null,\n error: null,\n email: null,\n status: \"unauthenticated\",\n requiresVerification,\n })\n \n if (shouldRedirect(pathname || \"\", false) && initialLoad) {\n redirectToLogin()\n }\n }\n } catch (error){\n console.error(\"Auth state change error:\", error)\n if (mounted) {\n handleSignOut(error instanceof Error ? error : new Error(\"Authentication error occurred\"))\n }\n } finally {\n initialLoad = false\n }\n })\n \n return () => {\n mounted = false\n unsubscribe()\n }\n }, [auth, handleSignOut, redirectToLogin, requiresVerification, pathname, isRedirecting, shouldRedirect])\n\n const contextValue: TernSecureCtxValue = useMemo(() => ({\n ...authState,\n signOut: handleSignOut,\n setEmail,\n getAuthError,\n redirectToLogin,\n }), [authState, handleSignOut, setEmail, getAuthError, redirectToLogin]);\n\n if (!authState.isLoaded) {\n return (\n <TernSecureCtx.Provider value={contextValue}>\n {loadingComponent || (\n <div aria-live=\"polite\" aria-busy=\"true\">\n <span className=\"sr-only\">Loading authentication state...</span>\n </div>\n )}\n </TernSecureCtx.Provider>\n );\n }\n\n return (\n <TernSecureCtx.Provider value={contextValue}>\n {children}\n </TernSecureCtx.Provider>\n )\n}"],"mappings":";AAqRY;AAnRZ,SAAgB,UAAU,WAAW,SAAS,mBAAmB;AACjE,SAAS,sBAAsB;AAC/B,SAAS,0BAAgC;AACzC,SAAS,qBAAyC;AAGlD,SAAS,WAAW,mBAAmB;AACvC,SAAS,iBAAiB,iBAAiB,mBAAkB;AAC7D,SAAS,uBAAuB;AA4BzB,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA,YAAY,QAAQ,IAAI,4BAA4B;AAAA,EACpD,aAAa,QAAQ,IAAI,4BAA4B;AAAA,EACrD;AAAA,EACA;AACF,GAAkC;AAChC,QAAM,OAAO,QAAQ,MAAM,gBAAgB,CAAC,CAAC;AAC7C,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAC7B,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK;AAExD,QAAM,CAAC,WAAW,YAAY,IAAI,SAA0B,OAAO;AAAA,IACjE,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,OAAO;AAAA,IACP,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,OAAO;AAAA,IACP,OAAO;AAAA,IACP,QAAQ;AAAA,IACR;AAAA,EACF,EAAE;AAEF,QAAM,2BAA2B;AAAA,IAC/B,CAACA,YAAmB,aAAqB,gBAAwB,oBAAoC;AACnG,YAAM,UAAU,OAAO,SAAS;AAChC,YAAM,YAAY,IAAI,IAAIA,YAAW,OAAO;AAG5C,UAAI,CAAC,YAAY,SAAS,cAAc,KAAK,CAAC,YAAY,SAAS,eAAe,GAAG;AACnF,kBAAU,aAAa,IAAI,YAAY,WAAW;AAAA,MACpD;AACA,aAAO,UAAU,SAAS;AAAA,IAC5B;AAAA,IACA,CAAC;AAAA,EACH;AAGA,QAAM,iB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AAd,EAAuB,OAAO,cAC7B,UACF;AAEN;","names":["loginPath","pathname"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/boundary/TernSecureCtx.tsx"],"sourcesContent":["\"use client\"\n\nimport { createContext, useContext } from 'react'\nimport { ternSecureAuth } from '../utils/client-init';\nimport { User } from 'firebase/auth';\nimport { type TernSecureState } from '../types';\n\nexport const TernSecureUser = (): User | null => {\n return ternSecureAuth.currentUser;\n}\n\nexport interface TernSecureCtxValue extends TernSecureState {\n signOut: () => Promise<void>\n setEmail: (email: string) => void\n}\n\nexport const TernSecureCtx = createContext<TernSecureCtxValue | null>(null)\n\nTernSecureCtx.displayName = 'TernSecureCtx'\n\nexport const useTernSecure = (hookName: string) => {\n const context = useContext(TernSecureCtx)\n \n if (!context) {\n throw new Error(\n `${hookName} must be used within TernSecureProvider`\n )\n }\n\n return context\n}\n\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAC1C,SAAS,sBAAsB;AAIxB,MAAM,iBAAiB,MAAmB;AAC/C,SAAO,eAAe;AACxB;AAOO,MAAM,gBAAgB,cAAyC,IAAI;AAE1E,cAAc,cAAc;AAErB,MAAM,gBAAgB,CAAC,aAAqB;AACjD,QAAM,UAAU,WAAW,aAAa;AAExC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR,GAAG,QAAQ;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/boundary/TernSecureCtx.tsx"],"sourcesContent":["\"use client\"\n\nimport { createContext, useContext } from 'react'\nimport { ternSecureAuth } from '../utils/client-init';\nimport { User } from 'firebase/auth';\nimport type { TernSecureState, SignInResponse } from '../types';\n\nexport const TernSecureUser = (): User | null => {\n return ternSecureAuth.currentUser;\n}\n\nexport interface TernSecureCtxValue extends TernSecureState {\n signOut: () => Promise<void>\n setEmail: (email: string) => void\n getAuthError: () => SignInResponse\n redirectToLogin: () => void\n}\n\nexport const TernSecureCtx = createContext<TernSecureCtxValue | null>(null)\n\nTernSecureCtx.displayName = 'TernSecureCtx'\n\nexport const useTernSecure = (hookName: string) => {\n const context = useContext(TernSecureCtx)\n \n if (!context) {\n throw new Error(\n `${hookName} must be used within TernSecureProvider`\n )\n }\n\n return context\n}\n\n"],"mappings":";AAEA,SAAS,eAAe,kBAAkB;AAC1C,SAAS,sBAAsB;AAIxB,MAAM,iBAAiB,MAAmB;AAC/C,SAAO,eAAe;AACxB;AASO,MAAM,gBAAgB,cAAyC,IAAI;AAE1E,cAAc,cAAc;AAErB,MAAM,gBAAgB,CAAC,aAAqB;AACjD,QAAM,UAAU,WAAW,aAAa;AAExC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR,GAAG,QAAQ;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}