@tern-secure/nextjs 3.3.5 → 3.4.1
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/cjs/app-router/client/TernSecureProvider.js +33 -0
- package/dist/cjs/app-router/client/TernSecureProvider.js.map +1 -0
- package/dist/cjs/app-router/client/actions.js +180 -0
- package/dist/cjs/app-router/client/actions.js.map +1 -0
- package/dist/cjs/app-router/route-handler/internal-route.js +45 -0
- package/dist/cjs/app-router/route-handler/internal-route.js.map +1 -0
- package/dist/cjs/app-router/server/auth.js +71 -0
- package/dist/cjs/app-router/server/auth.js.map +1 -0
- package/dist/cjs/app-router/server/index.js +42 -0
- package/dist/cjs/app-router/server/index.js.map +1 -0
- package/dist/cjs/app-router/server/sessionTernSecure.js +159 -0
- package/dist/cjs/app-router/server/sessionTernSecure.js.map +1 -0
- package/dist/cjs/app-router/server/ternSecureMiddleware.js +50 -0
- package/dist/cjs/app-router/server/ternSecureMiddleware.js.map +1 -0
- package/dist/cjs/boundary/TernSecureClientProvider.js +107 -0
- package/dist/cjs/boundary/TernSecureClientProvider.js.map +1 -0
- package/dist/cjs/boundary/TernSecureCtx.js +49 -0
- package/dist/cjs/boundary/TernSecureCtx.js.map +1 -0
- package/dist/cjs/boundary/hooks/useAuth.js +51 -0
- package/dist/cjs/boundary/hooks/useAuth.js.map +1 -0
- package/dist/cjs/boundary/hooks/useSignUp.js +40 -0
- package/dist/cjs/boundary/hooks/useSignUp.js.map +1 -0
- package/dist/cjs/boundary/hooks/useUser.js +44 -0
- package/dist/cjs/boundary/hooks/useUser.js.map +1 -0
- package/dist/cjs/components/background.js +65 -0
- package/dist/cjs/components/background.js.map +1 -0
- package/dist/cjs/components/sign-in.js +242 -0
- package/dist/cjs/components/sign-in.js.map +1 -0
- package/dist/cjs/components/sign-out.js +69 -0
- package/dist/cjs/components/sign-out.js.map +1 -0
- package/dist/cjs/components/sign-up.js +328 -0
- package/dist/cjs/components/sign-up.js.map +1 -0
- package/dist/cjs/components/ui/alert.js +88 -0
- package/dist/cjs/components/ui/alert.js.map +1 -0
- package/dist/cjs/components/ui/button.js +84 -0
- package/dist/cjs/components/ui/button.js.map +1 -0
- package/dist/cjs/components/ui/card.js +101 -0
- package/dist/cjs/components/ui/card.js.map +1 -0
- package/dist/cjs/components/ui/input.js +58 -0
- package/dist/cjs/components/ui/input.js.map +1 -0
- package/dist/cjs/components/ui/label.js +55 -0
- package/dist/cjs/components/ui/label.js.map +1 -0
- package/dist/cjs/components/ui/separator.js +59 -0
- package/dist/cjs/components/ui/separator.js.map +1 -0
- package/dist/cjs/components/verify.js +195 -0
- package/dist/cjs/components/verify.js.map +1 -0
- package/dist/cjs/errors.js +41 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +59 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/utils.d.js +17 -0
- package/dist/cjs/lib/utils.d.js.map +1 -0
- package/dist/cjs/lib/utils.js +33 -0
- package/dist/cjs/lib/utils.js.map +1 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/admin-init.js +57 -0
- package/dist/cjs/utils/admin-init.js.map +1 -0
- package/dist/cjs/utils/client-init.js +49 -0
- package/dist/cjs/utils/client-init.js.map +1 -0
- package/dist/cjs/utils/config.js +113 -0
- package/dist/cjs/utils/config.js.map +1 -0
- package/dist/cjs/utils/construct.js +63 -0
- package/dist/cjs/utils/construct.js.map +1 -0
- package/dist/cjs/utils/create-styles.js +149 -0
- package/dist/cjs/utils/create-styles.js.map +1 -0
- package/dist/esm/app-router/client/TernSecureProvider.js +9 -0
- package/dist/esm/app-router/client/TernSecureProvider.js.map +1 -0
- package/dist/esm/app-router/client/actions.js +151 -0
- package/dist/esm/app-router/client/actions.js.map +1 -0
- package/dist/esm/app-router/route-handler/internal-route.js +20 -0
- package/dist/esm/app-router/route-handler/internal-route.js.map +1 -0
- package/dist/esm/app-router/server/auth.js +47 -0
- package/dist/esm/app-router/server/auth.js.map +1 -0
- package/dist/esm/app-router/server/index.js +13 -0
- package/dist/esm/app-router/server/index.js.map +1 -0
- package/dist/esm/app-router/server/sessionTernSecure.js +129 -0
- package/dist/esm/app-router/server/sessionTernSecure.js.map +1 -0
- package/dist/esm/app-router/server/ternSecureMiddleware.js +26 -0
- package/dist/esm/app-router/server/ternSecureMiddleware.js.map +1 -0
- package/dist/esm/boundary/TernSecureClientProvider.js +83 -0
- package/dist/esm/boundary/TernSecureClientProvider.js.map +1 -0
- package/dist/esm/boundary/TernSecureCtx.js +23 -0
- package/dist/esm/boundary/TernSecureCtx.js.map +1 -0
- package/dist/esm/boundary/hooks/useAuth.js +27 -0
- package/dist/esm/boundary/hooks/useAuth.js.map +1 -0
- package/dist/esm/boundary/hooks/useSignUp.js +16 -0
- package/dist/esm/boundary/hooks/useSignUp.js.map +1 -0
- package/dist/esm/boundary/hooks/useUser.js +20 -0
- package/dist/esm/boundary/hooks/useUser.js.map +1 -0
- package/dist/esm/components/background.js +41 -0
- package/dist/esm/components/background.js.map +1 -0
- package/dist/esm/components/sign-in.js +218 -0
- package/dist/esm/components/sign-in.js.map +1 -0
- package/dist/esm/components/sign-out.js +45 -0
- package/dist/esm/components/sign-out.js.map +1 -0
- package/dist/esm/components/sign-up.js +294 -0
- package/dist/esm/components/sign-up.js.map +1 -0
- package/dist/esm/components/ui/alert.js +52 -0
- package/dist/esm/components/ui/alert.js.map +1 -0
- package/dist/esm/components/ui/button.js +49 -0
- package/dist/esm/components/ui/button.js.map +1 -0
- package/dist/esm/components/ui/card.js +62 -0
- package/dist/esm/components/ui/card.js.map +1 -0
- package/dist/esm/components/ui/input.js +24 -0
- package/dist/esm/components/ui/input.js.map +1 -0
- package/dist/esm/components/ui/label.js +21 -0
- package/dist/esm/components/ui/label.js.map +1 -0
- package/dist/esm/components/ui/separator.js +25 -0
- package/dist/esm/components/ui/separator.js.map +1 -0
- package/dist/esm/components/verify.js +161 -0
- package/dist/esm/components/verify.js.map +1 -0
- package/dist/esm/errors.js +16 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +24 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/utils.d.js +1 -0
- package/dist/esm/lib/utils.d.js.map +1 -0
- package/dist/esm/lib/utils.js +9 -0
- package/dist/esm/lib/utils.js.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/admin-init.js +22 -0
- package/dist/esm/utils/admin-init.js.map +1 -0
- package/dist/esm/utils/client-init.js +22 -0
- package/dist/esm/utils/client-init.js.map +1 -0
- package/dist/esm/utils/config.js +84 -0
- package/dist/esm/utils/config.js.map +1 -0
- package/dist/esm/utils/construct.js +37 -0
- package/dist/esm/utils/construct.js.map +1 -0
- package/dist/esm/utils/create-styles.js +123 -0
- package/dist/esm/utils/create-styles.js.map +1 -0
- package/dist/types/app-router/client/TernSecureProvider.d.ts +26 -0
- package/dist/types/app-router/client/TernSecureProvider.d.ts.map +1 -0
- package/dist/types/app-router/client/actions.d.ts +49 -0
- package/dist/types/app-router/client/actions.d.ts.map +1 -0
- package/dist/types/app-router/route-handler/internal-route.d.ts +9 -0
- package/dist/types/app-router/route-handler/internal-route.d.ts.map +1 -0
- package/dist/types/app-router/server/auth.d.ts +7 -0
- package/dist/types/app-router/server/auth.d.ts.map +1 -0
- package/dist/types/app-router/server/index.d.ts +5 -0
- package/dist/types/app-router/server/index.d.ts.map +1 -0
- package/dist/types/app-router/server/sessionTernSecure.d.ts +37 -0
- package/dist/types/app-router/server/sessionTernSecure.d.ts.map +1 -0
- package/dist/types/app-router/server/ternSecureMiddleware.d.ts +7 -0
- package/dist/types/app-router/server/ternSecureMiddleware.d.ts.map +1 -0
- package/dist/types/boundary/TernSecureClientProvider.d.ts +11 -0
- package/dist/types/boundary/TernSecureClientProvider.d.ts.map +1 -0
- package/dist/types/boundary/TernSecureCtx.d.ts +17 -0
- package/dist/types/boundary/TernSecureCtx.d.ts.map +1 -0
- package/dist/types/boundary/hooks/useAuth.d.ts +11 -0
- package/dist/types/boundary/hooks/useAuth.d.ts.map +1 -0
- package/dist/types/boundary/hooks/useSignUp.d.ts +5 -0
- package/dist/types/boundary/hooks/useSignUp.d.ts.map +1 -0
- package/dist/types/boundary/hooks/useUser.d.ts +7 -0
- package/dist/types/boundary/hooks/useUser.d.ts.map +1 -0
- package/dist/types/components/background.d.ts +2 -0
- package/dist/types/components/background.d.ts.map +1 -0
- package/dist/types/components/sign-in.d.ts +18 -0
- package/dist/types/components/sign-in.d.ts.map +1 -0
- package/dist/types/components/sign-out.d.ts +10 -0
- package/dist/types/components/sign-out.d.ts.map +1 -0
- package/dist/types/components/sign-up.d.ts +7 -0
- package/dist/types/components/sign-up.d.ts.map +1 -0
- package/dist/types/components/ui/alert.d.ts +9 -0
- package/dist/types/components/ui/alert.d.ts.map +1 -0
- package/dist/types/components/ui/button.d.ts +12 -0
- package/dist/types/components/ui/button.d.ts.map +1 -0
- package/dist/types/components/ui/card.d.ts +9 -0
- package/dist/types/components/ui/card.d.ts.map +1 -0
- package/dist/types/components/ui/input.d.ts +4 -0
- package/dist/types/components/ui/input.d.ts.map +1 -0
- package/dist/types/components/ui/label.d.ts +6 -0
- package/dist/types/components/ui/label.d.ts.map +1 -0
- package/dist/types/components/ui/separator.d.ts +5 -0
- package/dist/types/components/ui/separator.d.ts.map +1 -0
- package/dist/types/components/verify.d.ts +2 -0
- package/dist/types/components/verify.d.ts.map +1 -0
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/utils.d.ts +3 -0
- package/dist/types/lib/utils.d.ts.map +1 -0
- package/dist/types/types.d.ts +63 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/admin-init.d.ts +4 -0
- package/dist/types/utils/admin-init.d.ts.map +1 -0
- package/dist/types/utils/client-init.d.ts +5 -0
- package/dist/types/utils/client-init.d.ts.map +1 -0
- package/dist/types/utils/config.d.ts +35 -0
- package/dist/types/utils/config.d.ts.map +1 -0
- package/dist/types/utils/construct.d.ts +22 -0
- package/dist/types/utils/construct.d.ts.map +1 -0
- package/dist/types/utils/create-styles.d.ts +99 -0
- package/dist/types/utils/create-styles.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
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 TernSecureProvider_exports = {};
|
|
20
|
+
__export(TernSecureProvider_exports, {
|
|
21
|
+
TernSecureProvider: () => TernSecureProvider
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(TernSecureProvider_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_TernSecureClientProvider = require("../../boundary/TernSecureClientProvider");
|
|
26
|
+
async function TernSecureProvider({ children }) {
|
|
27
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TernSecureClientProvider.TernSecureClientProvider, { children });
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
TernSecureProvider
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=TernSecureProvider.js.map
|
|
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCI;AAlCJ,sCAAyC;AAgCzC,eAAsB,mBAAmB,EAAE,SAAS,GAAkC;AACpF,SACE,4CAAC,4DACI,UACL;AAEJ;","names":[]}
|
|
@@ -0,0 +1,180 @@
|
|
|
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 actions_exports = {};
|
|
20
|
+
__export(actions_exports, {
|
|
21
|
+
createUser: () => createUser,
|
|
22
|
+
handleAuthRedirectResult: () => handleAuthRedirectResult,
|
|
23
|
+
resendEmailVerification: () => resendEmailVerification,
|
|
24
|
+
signInWithEmail: () => signInWithEmail,
|
|
25
|
+
signInWithMicrosoft: () => signInWithMicrosoft,
|
|
26
|
+
signInWithRedirectGoogle: () => signInWithRedirectGoogle
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(actions_exports);
|
|
29
|
+
var import_client_init = require("../../utils/client-init");
|
|
30
|
+
var import_auth = require("firebase/auth");
|
|
31
|
+
var import_sessionTernSecure = require("../server/sessionTernSecure");
|
|
32
|
+
async function createUser(email, password) {
|
|
33
|
+
const auth = (0, import_client_init.TernSecureAuth)();
|
|
34
|
+
try {
|
|
35
|
+
const actionCodeSettings = {
|
|
36
|
+
url: `${window.location.origin}/sign-in`,
|
|
37
|
+
handleCodeInApp: true
|
|
38
|
+
};
|
|
39
|
+
const userCredential = await (0, import_auth.createUserWithEmailAndPassword)(auth, email, password);
|
|
40
|
+
await (0, import_auth.sendEmailVerification)(userCredential.user, actionCodeSettings);
|
|
41
|
+
return { success: true, message: "Account created successfully.", user: userCredential.user };
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
switch (error.message) {
|
|
45
|
+
case "auth/too-many-requests":
|
|
46
|
+
throw new Error("Too many attempts. Please try again later.");
|
|
47
|
+
case "auth/network-request-failed":
|
|
48
|
+
throw new Error("Network disconnected. Please try again later.");
|
|
49
|
+
case "auth/email-already-in-use":
|
|
50
|
+
throw new Error("Email is already registered.");
|
|
51
|
+
case "auth/invalid-email":
|
|
52
|
+
throw new Error("Invalid email address.");
|
|
53
|
+
case "auth/operation-not-allowed":
|
|
54
|
+
throw new Error("Email/password accounts are not enabled.");
|
|
55
|
+
case "auth/weak-password":
|
|
56
|
+
throw new Error("Password is too weak.");
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(error.message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Failed to create account");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function signInWithEmail(email, password) {
|
|
65
|
+
const auth = (0, import_client_init.TernSecureAuth)();
|
|
66
|
+
try {
|
|
67
|
+
const UserCredential = await (0, import_auth.signInWithEmailAndPassword)(auth, email, password);
|
|
68
|
+
const idToken = await UserCredential.user.getIdToken();
|
|
69
|
+
const res = await (0, import_sessionTernSecure.createSessionCookie)(idToken);
|
|
70
|
+
if (res.success) {
|
|
71
|
+
return { success: true, message: "Connected." };
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error(res.message);
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to sign in";
|
|
77
|
+
throw new Error(errorMessage);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function signInWithRedirectGoogle() {
|
|
81
|
+
const auth = (0, import_client_init.TernSecureAuth)();
|
|
82
|
+
const provider = new import_auth.GoogleAuthProvider();
|
|
83
|
+
provider.setCustomParameters({
|
|
84
|
+
login_hint: "user@example.com",
|
|
85
|
+
prompt: "select_account"
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
await (0, import_auth.signInWithRedirect)(auth, provider);
|
|
89
|
+
return { success: true, message: "Redirect initiated" };
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error("Error during Google sign-in:", error);
|
|
92
|
+
return { success: false, error: "Failed to sign in with Google" };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function signInWithMicrosoft() {
|
|
96
|
+
const auth = (0, import_client_init.TernSecureAuth)();
|
|
97
|
+
const provider = new import_auth.OAuthProvider("microsoft.com");
|
|
98
|
+
provider.setCustomParameters({
|
|
99
|
+
prompt: "consent"
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
await (0, import_auth.signInWithRedirect)(auth, provider);
|
|
103
|
+
return { success: true, message: "Redirect initiated" };
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error("Error during Google sign-in:", error);
|
|
106
|
+
return { success: false, error: "Failed to sign in with Google" };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function handleAuthRedirectResult() {
|
|
110
|
+
const auth = (0, import_client_init.TernSecureAuth)();
|
|
111
|
+
try {
|
|
112
|
+
const result = await (0, import_auth.getRedirectResult)(auth);
|
|
113
|
+
if (result) {
|
|
114
|
+
const user = result.user;
|
|
115
|
+
return { success: true, user };
|
|
116
|
+
} else {
|
|
117
|
+
return { success: false, error: "No redirect result" };
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error handling auth redirect result:", error);
|
|
121
|
+
return { success: false, error: error.message || "Failed to handle auth redirect", code: error.code };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function resendEmailVerification() {
|
|
125
|
+
const auth = (0, import_client_init.TernSecureAuth)();
|
|
126
|
+
try {
|
|
127
|
+
const user = auth.currentUser;
|
|
128
|
+
if (!user) {
|
|
129
|
+
throw new Error("No user found. Please try signing up again.");
|
|
130
|
+
}
|
|
131
|
+
await user.reload();
|
|
132
|
+
if (user.emailVerified) {
|
|
133
|
+
return {
|
|
134
|
+
success: true,
|
|
135
|
+
message: "Email is already verified. You can sign in.",
|
|
136
|
+
isVerified: true
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const actionCodeSettings = {
|
|
140
|
+
url: `${window.location.origin}/sign-in`,
|
|
141
|
+
handleCodeInApp: true
|
|
142
|
+
};
|
|
143
|
+
await (0, import_auth.sendEmailVerification)(user, actionCodeSettings);
|
|
144
|
+
return {
|
|
145
|
+
success: true,
|
|
146
|
+
message: "Verification email sent successfully.",
|
|
147
|
+
isVerified: false
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (error instanceof Error) {
|
|
151
|
+
switch (error.message) {
|
|
152
|
+
case "auth/too-many-requests":
|
|
153
|
+
throw new Error("Too many attempts. Please try again later.");
|
|
154
|
+
case "auth/network-request-failed":
|
|
155
|
+
throw new Error("Network disconnected. Please try again later.");
|
|
156
|
+
case "auth/email-already-in-use":
|
|
157
|
+
throw new Error("Email is already registered.");
|
|
158
|
+
case "auth/invalid-email":
|
|
159
|
+
throw new Error("Invalid email address.");
|
|
160
|
+
case "auth/operation-not-allowed":
|
|
161
|
+
throw new Error("Email/password accounts are not enabled.");
|
|
162
|
+
case "auth/weak-password":
|
|
163
|
+
throw new Error("Password is too weak.");
|
|
164
|
+
default:
|
|
165
|
+
throw new Error(error.message);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
throw new Error("Failed to resend verification email.");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
172
|
+
0 && (module.exports = {
|
|
173
|
+
createUser,
|
|
174
|
+
handleAuthRedirectResult,
|
|
175
|
+
resendEmailVerification,
|
|
176
|
+
signInWithEmail,
|
|
177
|
+
signInWithMicrosoft,
|
|
178
|
+
signInWithRedirectGoogle
|
|
179
|
+
});
|
|
180
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +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 { createSessionCookie } from '../server/sessionTernSecure'\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){\n const auth = TernSecureAuth()\n try {\n const UserCredential = await signInWithEmailAndPassword(auth, email, password)\n const idToken = await UserCredential.user.getIdToken();\n\n const res = await createSessionCookie(idToken);\n\n if(res.success) {\n return { success: true, message: 'Connected.' };\n } else {\n throw new Error(res.message);\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA+B;AAC/B,kBAA4K;AAC5K,+BAAoC;AAEpC,eAAsB,WAAW,OAAe,UAA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ClB,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,cAAM,mCAAsB,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":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 internal_route_exports = {};
|
|
20
|
+
__export(internal_route_exports, {
|
|
21
|
+
handleInternalRoute: () => handleInternalRoute,
|
|
22
|
+
internalRoutes: () => internalRoutes
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(internal_route_exports);
|
|
25
|
+
var import_verify = require("../../components/verify");
|
|
26
|
+
const internalRoutes = {
|
|
27
|
+
verify: {
|
|
28
|
+
pattern: /^\/sign-up\/verify$/,
|
|
29
|
+
component: import_verify.Verify
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function handleInternalRoute(pathname) {
|
|
33
|
+
for (const [key, route] of Object.entries(internalRoutes)) {
|
|
34
|
+
if (route.pattern.test(pathname)) {
|
|
35
|
+
return route.component;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
handleInternalRoute,
|
|
43
|
+
internalRoutes
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=internal-route.js.map
|
|
@@ -0,0 +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 verify: {\n pattern: /^\\/sign-up\\/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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAGhB,MAAM,iBAAiB;AAAA,EAC5B,QAAQ;AAAA,IACN,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":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var auth_exports = {};
|
|
21
|
+
__export(auth_exports, {
|
|
22
|
+
auth: () => auth
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(auth_exports);
|
|
25
|
+
var import_headers = require("next/headers");
|
|
26
|
+
var import_sessionTernSecure = require("./sessionTernSecure");
|
|
27
|
+
async function auth() {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
try {
|
|
30
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
31
|
+
const sessionCookie = (_a = cookieStore.get("_session_cookie")) == null ? void 0 : _a.value;
|
|
32
|
+
if (sessionCookie) {
|
|
33
|
+
const sessionResult = await (0, import_sessionTernSecure.verifyTernSessionCookie)(sessionCookie);
|
|
34
|
+
if (sessionResult.valid) {
|
|
35
|
+
return {
|
|
36
|
+
userId: sessionResult.uid,
|
|
37
|
+
token: sessionCookie,
|
|
38
|
+
error: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const idToken = (_b = cookieStore.get("_session_token")) == null ? void 0 : _b.value;
|
|
43
|
+
if (idToken) {
|
|
44
|
+
const tokenResult = await (0, import_sessionTernSecure.verifyTernIdToken)(idToken);
|
|
45
|
+
if (tokenResult.valid) {
|
|
46
|
+
return {
|
|
47
|
+
userId: (_c = tokenResult.uid) != null ? _c : null,
|
|
48
|
+
token: idToken,
|
|
49
|
+
error: null
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
userId: null,
|
|
55
|
+
token: null,
|
|
56
|
+
error: new Error("No valid session or token found")
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("Error in auth function:", error);
|
|
60
|
+
return {
|
|
61
|
+
userId: null,
|
|
62
|
+
token: null,
|
|
63
|
+
error: error instanceof Error ? error : new Error("An unknown error occurred")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
auth
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/app-router/server/auth.ts"],"sourcesContent":["'use server'\n\nimport { cookies } from 'next/headers';\nimport { verifyTernIdToken, verifyTernSessionCookie } from './sessionTernSecure';\n\nexport interface AuthResult {\n userId: string | null;\n token: string | null;\n error: Error | null;\n}\n\nexport async function auth(): Promise<AuthResult> {\n try {\n const cookieStore = await cookies();\n const sessionCookie = cookieStore.get('_session_cookie')?.value;\n if (sessionCookie) {\n const sessionResult = await verifyTernSessionCookie(sessionCookie);\n if (sessionResult.valid) {\n return {\n userId: sessionResult.uid,\n token: sessionCookie,\n error: null\n };\n }\n }\n\n // If session cookie is not present or invalid, try the ID token\n const idToken = cookieStore.get('_session_token')?.value;\n if (idToken) {\n const tokenResult = await verifyTernIdToken(idToken);\n if (tokenResult.valid) {\n return {\n userId: tokenResult.uid ?? null,\n token: idToken,\n error: null\n };\n }\n }\n\n /// If both checks fail, return null values\n return {\n userId: null,\n token: null,\n error: new Error('No valid session or token found')\n };\n } catch (error) {\n console.error('Error in auth function:', error);\n return {\n userId: null,\n token: null,\n error: error instanceof Error ? error : new Error('An unknown error occurred')\n };\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAwB;AACxB,+BAA4D;AAQ5D,eAAsB,OAA4B;AAXlD;AAYE,MAAI;AACF,UAAM,cAAc,UAAM,wBAAQ;AAClC,UAAM,iBAAgB,iBAAY,IAAI,iBAAiB,MAAjC,mBAAoC;AAC1D,QAAI,eAAe;AACjB,YAAM,gBAAgB,UAAM,kDAAwB,aAAa;AACjE,UAAI,cAAc,OAAO;AACvB,eAAO;AAAA,UACL,QAAQ,cAAc;AAAA,UACtB,OAAO;AAAA,UACP,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAGA,UAAM,WAAU,iBAAY,IAAI,gBAAgB,MAAhC,mBAAmC;AACnD,QAAI,SAAS;AACX,YAAM,cAAc,UAAM,4CAAkB,OAAO;AACnD,UAAI,YAAY,OAAO;AACrB,eAAO;AAAA,UACL,SAAQ,iBAAY,QAAZ,YAAmB;AAAA,UAC3B,OAAO;AAAA,UACP,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,OAAO,IAAI,MAAM,iCAAiC;AAAA,IACpD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,2BAA2B;AAAA,IAC/E;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 server_exports = {};
|
|
20
|
+
__export(server_exports, {
|
|
21
|
+
adminTernSecureAuth: () => import_admin_init.adminTernSecureAuth,
|
|
22
|
+
adminTernSecureDb: () => import_admin_init.adminTernSecureDb,
|
|
23
|
+
auth: () => import_auth.auth,
|
|
24
|
+
createSessionCookie: () => import_sessionTernSecure.createSessionCookie,
|
|
25
|
+
ternSecureMiddleware: () => import_ternSecureMiddleware.ternSecureMiddleware,
|
|
26
|
+
verifyTernSessionCookie: () => import_sessionTernSecure.verifyTernSessionCookie
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(server_exports);
|
|
29
|
+
var import_admin_init = require("../../utils/admin-init");
|
|
30
|
+
var import_ternSecureMiddleware = require("./ternSecureMiddleware");
|
|
31
|
+
var import_sessionTernSecure = require("./sessionTernSecure");
|
|
32
|
+
var import_auth = require("./auth");
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
adminTernSecureAuth,
|
|
36
|
+
adminTernSecureDb,
|
|
37
|
+
auth,
|
|
38
|
+
createSessionCookie,
|
|
39
|
+
ternSecureMiddleware,
|
|
40
|
+
verifyTernSessionCookie
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/app-router/server/index.ts"],"sourcesContent":["export { adminTernSecureAuth, adminTernSecureDb } from '../../utils/admin-init'\nexport { ternSecureMiddleware } from './ternSecureMiddleware'\nexport { verifyTernSessionCookie, createSessionCookie } from './sessionTernSecure'\nexport { auth } from './auth'"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAuD;AACvD,kCAAqC;AACrC,+BAA6D;AAC7D,kBAAqB;","names":[]}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var sessionTernSecure_exports = {};
|
|
21
|
+
__export(sessionTernSecure_exports, {
|
|
22
|
+
clearSessionCookie: () => clearSessionCookie,
|
|
23
|
+
createSessionCookie: () => createSessionCookie,
|
|
24
|
+
getIdToken: () => getIdToken,
|
|
25
|
+
getServerSessionCookie: () => getServerSessionCookie,
|
|
26
|
+
setServerSession: () => setServerSession,
|
|
27
|
+
verifyTernIdToken: () => verifyTernIdToken,
|
|
28
|
+
verifyTernSessionCookie: () => verifyTernSessionCookie
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(sessionTernSecure_exports);
|
|
31
|
+
var import_headers = require("next/headers");
|
|
32
|
+
var import_admin_init = require("../../utils/admin-init");
|
|
33
|
+
async function createSessionCookie(idToken) {
|
|
34
|
+
try {
|
|
35
|
+
const expiresIn = 60 * 60 * 24 * 5 * 1e3;
|
|
36
|
+
const sessionCookie = await import_admin_init.adminTernSecureAuth.createSessionCookie(idToken, { expiresIn });
|
|
37
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
38
|
+
cookieStore.set("_session_cookie", sessionCookie, {
|
|
39
|
+
maxAge: expiresIn,
|
|
40
|
+
httpOnly: true,
|
|
41
|
+
secure: process.env.NODE_ENV === "production",
|
|
42
|
+
path: "/"
|
|
43
|
+
});
|
|
44
|
+
return { success: true, message: "Session created" };
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return { success: false, message: "Failed to create session" };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function getServerSessionCookie() {
|
|
50
|
+
var _a;
|
|
51
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
52
|
+
const sessionCookie = (_a = cookieStore.get("_session_cookie")) == null ? void 0 : _a.value;
|
|
53
|
+
if (!sessionCookie) {
|
|
54
|
+
throw new Error("No session cookie found");
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const decondeClaims = await import_admin_init.adminTernSecureAuth.verifySessionCookie(sessionCookie, true);
|
|
58
|
+
return {
|
|
59
|
+
token: sessionCookie,
|
|
60
|
+
userId: decondeClaims.uid
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Error verifying session:", error);
|
|
64
|
+
throw new Error("Invalid Session");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function getIdToken() {
|
|
68
|
+
var _a;
|
|
69
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
70
|
+
const token = (_a = cookieStore.get("_session_token")) == null ? void 0 : _a.value;
|
|
71
|
+
if (!token) {
|
|
72
|
+
throw new Error("No session cookie found");
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const decodedClaims = await import_admin_init.adminTernSecureAuth.verifyIdToken(token);
|
|
76
|
+
return {
|
|
77
|
+
token,
|
|
78
|
+
userId: decodedClaims.uid
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Error verifying session:", error);
|
|
82
|
+
throw new Error("Invalid Session");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function setServerSession(token) {
|
|
86
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
87
|
+
cookieStore.set("_session", token, {
|
|
88
|
+
httpOnly: true,
|
|
89
|
+
secure: process.env.NODE_ENV === "production",
|
|
90
|
+
sameSite: "strict",
|
|
91
|
+
maxAge: 60 * 60,
|
|
92
|
+
// 1 hour
|
|
93
|
+
path: "/"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function verifyTernIdToken(token) {
|
|
97
|
+
try {
|
|
98
|
+
const decodedToken = await import_admin_init.adminTernSecureAuth.verifyIdToken(token, true);
|
|
99
|
+
return { valid: true, uid: decodedToken.uid };
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof Error) {
|
|
102
|
+
const firebaseError = error;
|
|
103
|
+
if (error.name === "FirebaseAuthError") {
|
|
104
|
+
switch (firebaseError.code) {
|
|
105
|
+
case "auth/id-token-expired":
|
|
106
|
+
return { valid: false, error: "Token has expired" };
|
|
107
|
+
case "auth/id-token-revoked":
|
|
108
|
+
return { valid: false, error: "Token has been revoked" };
|
|
109
|
+
case "auth/user-disabled":
|
|
110
|
+
return { valid: false, error: "User account has been disabled" };
|
|
111
|
+
default:
|
|
112
|
+
return { valid: false, error: "Invalid token" };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { valid: false, error: "Error verifying token" };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function verifyTernSessionCookie(session) {
|
|
120
|
+
try {
|
|
121
|
+
const res = await import_admin_init.adminTernSecureAuth.verifySessionCookie(session, true);
|
|
122
|
+
if (res) {
|
|
123
|
+
return { valid: true, uid: res.uid };
|
|
124
|
+
} else {
|
|
125
|
+
return { valid: false, error: "Invalid session" };
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return { error, valid: false };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function clearSessionCookie() {
|
|
132
|
+
var _a;
|
|
133
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
134
|
+
cookieStore.delete("_session_cookie");
|
|
135
|
+
cookieStore.delete("_session_token");
|
|
136
|
+
cookieStore.delete("_session");
|
|
137
|
+
try {
|
|
138
|
+
const sessionCookie = (_a = cookieStore.get("_session_cookie")) == null ? void 0 : _a.value;
|
|
139
|
+
if (sessionCookie) {
|
|
140
|
+
const decodedClaims = await import_admin_init.adminTernSecureAuth.verifySessionCookie(sessionCookie);
|
|
141
|
+
await import_admin_init.adminTernSecureAuth.revokeRefreshTokens(decodedClaims.uid);
|
|
142
|
+
}
|
|
143
|
+
return { success: true, message: "Session cleared successfully" };
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error("Error clearing session:", error);
|
|
146
|
+
return { success: true, message: "Session cookies cleared" };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
clearSessionCookie,
|
|
152
|
+
createSessionCookie,
|
|
153
|
+
getIdToken,
|
|
154
|
+
getServerSessionCookie,
|
|
155
|
+
setServerSession,
|
|
156
|
+
verifyTernIdToken,
|
|
157
|
+
verifyTernSessionCookie
|
|
158
|
+
});
|
|
159
|
+
//# sourceMappingURL=sessionTernSecure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/app-router/server/sessionTernSecure.ts"],"sourcesContent":["'use server'\n\nimport { cookies } from 'next/headers';\nimport { adminTernSecureAuth as adminAuth } from '../../utils/admin-init';\n\ninterface FirebaseAuthError extends Error {\n code?: string;\n}\n\nexport interface User {\n uid: string | null;\n email: string | null;\n }\n\nexport interface Session {\n user: User | null;\n token: string | null;\n error: Error | null;\n}\n\nexport async function createSessionCookie(idToken: string) {\n try {\n const expiresIn = 60 * 60 * 24 * 5 * 1000;\n const sessionCookie = await adminAuth.createSessionCookie(idToken, { expiresIn });\n\n const cookieStore = await cookies();\n cookieStore.set('_session_cookie', sessionCookie, {\n maxAge: expiresIn,\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n path: '/',\n });\n return { success: true, message: 'Session created' };\n } catch (error) {\n return { success: false, message: 'Failed to create session' };\n }\n}\n\n\n\nexport async function getServerSessionCookie() {\n const cookieStore = await cookies();\n const sessionCookie = cookieStore.get('_session_cookie')?.value;\n\n if (!sessionCookie) {\n throw new Error('No session cookie found')\n }\n \n try {\n const decondeClaims = await adminAuth.verifySessionCookie(sessionCookie, true)\n return {\n token: sessionCookie,\n userId: decondeClaims.uid\n }\n } catch (error) {\n console.error('Error verifying session:', error)\n throw new Error('Invalid Session')\n }\n}\n\n\nexport async function getIdToken() {\n const cookieStore = await cookies();\n const token = cookieStore.get('_session_token')?.value;\n\n if (!token) {\n throw new Error('No session cookie found')\n }\n \n try {\n const decodedClaims = await adminAuth.verifyIdToken(token)\n return {\n token: token,\n userId: decodedClaims.uid\n }\n } catch (error) {\n console.error('Error verifying session:', error)\n throw new Error('Invalid Session')\n }\n}\n\nexport async function setServerSession(token: string) {\n const cookieStore = await cookies();\n cookieStore.set('_session', token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'strict',\n maxAge: 60 * 60, // 1 hour\n path: '/',\n });\n }\n\n export async function verifyTernIdToken(token: string): Promise<{ valid: boolean; uid?: string; error?: string }> {\n try {\n const decodedToken = await adminAuth.verifyIdToken(token, true);\n return { valid: true, uid: decodedToken.uid };\n } catch (error) {\n if (error instanceof Error) {\n const firebaseError = error as FirebaseAuthError;\n if (error.name === 'FirebaseAuthError') {\n // Handle specific Firebase Auth errors\n switch (firebaseError.code) {\n case 'auth/id-token-expired':\n return { valid: false, error: 'Token has expired' };\n case 'auth/id-token-revoked':\n return { valid: false, error: 'Token has been revoked' };\n case 'auth/user-disabled':\n return { valid: false, error: 'User account has been disabled' };\n default:\n return { valid: false, error: 'Invalid token' };\n }\n }\n }\n return { valid: false, error: 'Error verifying token' };\n }\n }\n \n\n export async function verifyTernSessionCookie(session: string): Promise<{ valid: boolean; uid?: any; error?: any }>{\n try {\n const res = await adminAuth.verifySessionCookie(session, true);\n if (res) {\n return { valid: true, uid: res.uid };\n } else {\n return { valid: false, error: 'Invalid session'};\n }\n } catch (error) {\n return {error: error, valid: false}\n }\n }\n\n\n export async function clearSessionCookie() {\n const cookieStore = await cookies()\n \n cookieStore.delete('_session_cookie')\n cookieStore.delete('_session_token')\n cookieStore.delete('_session')\n \n try {\n // Verify if there's an active session before revoking\n const sessionCookie = cookieStore.get('_session_cookie')?.value\n if (sessionCookie) {\n // Get the decoded claims to get the user's ID\n const decodedClaims = await adminAuth.verifySessionCookie(sessionCookie)\n \n // Revoke all sessions for the user\n await adminAuth.revokeRefreshTokens(decodedClaims.uid)\n }\n \n return { success: true, message: 'Session cleared successfully' }\n } catch (error) {\n console.error('Error clearing session:', error)\n // Still return success even if revoking fails, as cookies are cleared\n return { success: true, message: 'Session cookies cleared' }\n }\n }\n\n\n\n/*\n export async function GET(request: NextRequest) {\n const cookieStore = await cookies();\n const sessionCookie = cookieStore.get('session')?.value\n \n if (!sessionCookie) {\n return NextResponse.json({ isAuthenticated: false }, { status: 401 })\n }\n \n try {\n const decodedClaims = await adminAuth.verifySessionCookie(sessionCookie, true)\n return NextResponse.json({ isAuthenticated: true, user: decodedClaims }, { status: 200 })\n } catch (error) {\n console.error('Error verifying session cookie:', error)\n return NextResponse.json({ isAuthenticated: false }, { status: 401 })\n }\n }\n\n*/"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAwB;AACxB,wBAAiD;AAiBjD,eAAsB,oBAAoB,SAAiB;AACzD,MAAI;AACF,UAAM,YAAY,KAAK,KAAK,KAAK,IAAI;AACnC,UAAM,gBAAgB,MAAM,kBAAAA,oBAAU,oBAAoB,SAAS,EAAE,UAAU,CAAC;AAEhF,UAAM,cAAc,UAAM,wBAAQ;AAClC,gBAAY,IAAI,mBAAmB,eAAe;AAAA,MAC9C,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,QAAQ,QAAQ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AAU,oBAAoB,aAAa;AAGvE,YAAM,kBAAAA,oBAAU,oBAAoB,cAAc,GAAG;AAAA,IACvD;AAEA,WAAO,EAAE,SAAS,MAAM,SAAS,+BAA+B;AAAA,EAClE,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAE9C,WAAO,EAAE,SAAS,MAAM,SAAS,0BAA0B;AAAA,EAC7D;AACF;","names":["adminAuth"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 ternSecureMiddleware_exports = {};
|
|
20
|
+
__export(ternSecureMiddleware_exports, {
|
|
21
|
+
ternSecureMiddleware: () => ternSecureMiddleware
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ternSecureMiddleware_exports);
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_auth = require("./auth");
|
|
26
|
+
function ternSecureMiddleware(options = {}) {
|
|
27
|
+
const { publicPaths = [], redirectTo = "/login" } = options;
|
|
28
|
+
return async function middleware(request) {
|
|
29
|
+
const { pathname } = request.nextUrl;
|
|
30
|
+
if (publicPaths.includes(pathname)) {
|
|
31
|
+
return import_server.NextResponse.next();
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const { userId, token, error } = await (0, import_auth.auth)();
|
|
35
|
+
if (error || !userId || !token) {
|
|
36
|
+
return import_server.NextResponse.redirect(new URL(redirectTo, request.url));
|
|
37
|
+
}
|
|
38
|
+
const response = import_server.NextResponse.next();
|
|
39
|
+
return response;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("Error in ternSecureMiddleware:", error);
|
|
42
|
+
return import_server.NextResponse.redirect(new URL(redirectTo, request.url));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
ternSecureMiddleware
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=ternSecureMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/app-router/server/ternSecureMiddleware.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { auth } from './auth';\n\nexport interface TernSecureMiddlewareOptions {\n publicPaths?: string[];\n redirectTo?: string;\n}\n\nexport function ternSecureMiddleware(options: TernSecureMiddlewareOptions = {}) {\n const { publicPaths = [], redirectTo = '/login' } = options;\n\n return async function middleware(request: NextRequest) {\n const { pathname } = request.nextUrl;\n\n // Check if the path is public\n if (publicPaths.includes(pathname)) {\n return NextResponse.next();\n }\n\n try {\n const { userId, token, error } = await auth();\n\n if (error || !userId || !token) {\n // If there's no valid session, redirect to login\n return NextResponse.redirect(new URL(redirectTo, request.url));\n }\n\n // If there's a valid session, allow the request to proceed\n const response = NextResponse.next();\n \n // Optionally, you can set headers here if needed\n // response.headers.set('X-User-ID', userId);\n\n return response;\n } catch (error) {\n console.error('Error in ternSecureMiddleware:', error);\n return NextResponse.redirect(new URL(redirectTo, request.url));\n }\n };\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,kBAAqB;AAOd,SAAS,qBAAqB,UAAuC,CAAC,GAAG;AAC9E,QAAM,EAAE,cAAc,CAAC,GAAG,aAAa,SAAS,IAAI;AAEpD,SAAO,eAAe,WAAW,SAAsB;AACrD,UAAM,EAAE,SAAS,IAAI,QAAQ;AAG7B,QAAI,YAAY,SAAS,QAAQ,GAAG;AAClC,aAAO,2BAAa,KAAK;AAAA,IAC3B;AAEA,QAAI;AACF,YAAM,EAAE,QAAQ,OAAO,MAAM,IAAI,UAAM,kBAAK;AAE5C,UAAI,SAAS,CAAC,UAAU,CAAC,OAAO;AAE9B,eAAO,2BAAa,SAAS,IAAI,IAAI,YAAY,QAAQ,GAAG,CAAC;AAAA,MAC/D;AAGA,YAAM,WAAW,2BAAa,KAAK;AAKnC,aAAO;AAAA,IACT,SAAS,OAAO;AACd,cAAQ,MAAM,kCAAkC,KAAK;AACrD,aAAO,2BAAa,SAAS,IAAI,IAAI,YAAY,QAAQ,GAAG,CAAC;AAAA,IAC/D;AAAA,EACF;AACF;","names":[]}
|