summaryrefslogtreecommitdiff
path: root/src/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions')
-rw-r--r--src/actions/deck.ts3
-rw-r--r--src/actions/login.ts31
2 files changed, 24 insertions, 10 deletions
diff --git a/src/actions/deck.ts b/src/actions/deck.ts
index e501f23..5812715 100644
--- a/src/actions/deck.ts
+++ b/src/actions/deck.ts
@@ -1,7 +1,6 @@
"use server";
-import ServerWord from "@/zoom/ServerWord";
-import { analyzeTHWord, segmentateThai } from "@/pages/api/nlp";
import db from "../lib/db";
+import { analyzeTHWord, segmentateThai } from "@/lib/calls/nlp";
export function shuffleDeck(userId: number, lessonId: number) {
const res = db.fetchLesson({ userId, lessonId, random: true });
diff --git a/src/actions/login.ts b/src/actions/login.ts
index ee15fe6..ed96f54 100644
--- a/src/actions/login.ts
+++ b/src/actions/login.ts
@@ -50,20 +50,35 @@ export async function postLogin(
console.log({ res });
if ("error" in res) return { error: res.error };
else {
- setCookie(res.ok as number);
- return { success: true };
+ // Set the cookie
+ await setCookie(res.ok as number);
+
+ // Return success for client-side handling
+ return {
+ success: true,
+ userId: res.ok,
+ redirect: "/"
+ };
}
}
async function setCookie(userId: number) {
+ // Set cookie expiry for 30 days
const COOKIE_EXPIRY = Date.now() + 1000 * 60 * 60 * 24 * 30;
- const COOKIE_OPTS = { expires: new Date(COOKIE_EXPIRY) };
-
+
+ // Generate a secure random token for the cookie
const { randomBytes } = await import("node:crypto");
- const cokistring = randomBytes(32).toBase64();
- const res = db.setCookie(cokistring, userId, COOKIE_EXPIRY);
+ const cookieToken = randomBytes(32).toString("base64");
+
+ // Store the cookie in the database
+ const res = db.setCookie(cookieToken, userId, COOKIE_EXPIRY);
+
+ // Set the cookie in the response
const { setCookie } = useCookies();
- setCookie(cokistring);
- // unstable_redirect("/");
+ setCookie(cookieToken);
+
+ console.log("Cookie set for user ID:", userId);
+
+ // Redirect is managed by client after successful login
}
// export async function postLogout(prev: number) {