Spaces:
Running
Running
Testing - logout clear cookies bug.
Browse files- chess-frontend/actions/auth.ts +15 -2
- src/seed/seed-users.ts +9 -9
- src/seed/setup.ts +1 -1
chess-frontend/actions/auth.ts
CHANGED
|
@@ -193,9 +193,22 @@ export async function logout() {
|
|
| 193 |
},
|
| 194 |
});
|
| 195 |
const cookieStore = await cookies();
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
});
|
|
|
|
| 199 |
redirect("/login");
|
| 200 |
}
|
| 201 |
|
|
|
|
| 193 |
},
|
| 194 |
});
|
| 195 |
const cookieStore = await cookies();
|
| 196 |
+
|
| 197 |
+
const cookiesToClear = [
|
| 198 |
+
"__Secure-better-auth.session_token",
|
| 199 |
+
"__Secure-better-auth.session_data",
|
| 200 |
+
"better-auth.session_token",
|
| 201 |
+
"better-auth.session_data",
|
| 202 |
+
];
|
| 203 |
+
|
| 204 |
+
cookiesToClear.forEach((name) => {
|
| 205 |
+
cookieStore.delete({
|
| 206 |
+
name,
|
| 207 |
+
path: "/",
|
| 208 |
+
secure: name.startsWith("__Secure-"),
|
| 209 |
+
});
|
| 210 |
});
|
| 211 |
+
|
| 212 |
redirect("/login");
|
| 213 |
}
|
| 214 |
|
src/seed/seed-users.ts
CHANGED
|
@@ -357,7 +357,7 @@ const generateUsername = (first: string, last: string) => {
|
|
| 357 |
};
|
| 358 |
|
| 359 |
async function seedIndianUsers(count: number) {
|
| 360 |
-
console.log("
|
| 361 |
|
| 362 |
try {
|
| 363 |
const existingUsers = await db.select().from(user).limit(1);
|
|
@@ -368,12 +368,12 @@ async function seedIndianUsers(count: number) {
|
|
| 368 |
return;
|
| 369 |
}
|
| 370 |
} catch (err) {
|
| 371 |
-
console.error("
|
| 372 |
console.error(err);
|
| 373 |
throw err;
|
| 374 |
}
|
| 375 |
|
| 376 |
-
console.log(`
|
| 377 |
|
| 378 |
const mockUsers = [];
|
| 379 |
|
|
@@ -392,9 +392,9 @@ async function seedIndianUsers(count: number) {
|
|
| 392 |
});
|
| 393 |
}
|
| 394 |
|
| 395 |
-
console.log("
|
| 396 |
|
| 397 |
-
const chunkSize =
|
| 398 |
let inserted = 0;
|
| 399 |
|
| 400 |
for (let i = 0; i < mockUsers.length; i += chunkSize) {
|
|
@@ -403,14 +403,14 @@ async function seedIndianUsers(count: number) {
|
|
| 403 |
try {
|
| 404 |
await db.insert(user).values(chunk);
|
| 405 |
inserted += chunk.length;
|
| 406 |
-
console.log(`
|
| 407 |
} catch (err) {
|
| 408 |
-
console.error("
|
| 409 |
console.error(JSON.stringify(err, null, 2));
|
| 410 |
}
|
| 411 |
}
|
| 412 |
|
| 413 |
-
console.log(`
|
| 414 |
}
|
| 415 |
|
| 416 |
seedIndianUsers(600)
|
|
@@ -419,6 +419,6 @@ seedIndianUsers(600)
|
|
| 419 |
process.exit(0);
|
| 420 |
})
|
| 421 |
.catch((err) => {
|
| 422 |
-
console.error("
|
| 423 |
process.exit(1);
|
| 424 |
});
|
|
|
|
| 357 |
};
|
| 358 |
|
| 359 |
async function seedIndianUsers(count: number) {
|
| 360 |
+
console.log("Verifying database status before seeding...");
|
| 361 |
|
| 362 |
try {
|
| 363 |
const existingUsers = await db.select().from(user).limit(1);
|
|
|
|
| 368 |
return;
|
| 369 |
}
|
| 370 |
} catch (err) {
|
| 371 |
+
console.error("Failed to query existing users table:");
|
| 372 |
console.error(err);
|
| 373 |
throw err;
|
| 374 |
}
|
| 375 |
|
| 376 |
+
console.log(`Database is empty. Generating ${count} mock users...`);
|
| 377 |
|
| 378 |
const mockUsers = [];
|
| 379 |
|
|
|
|
| 392 |
});
|
| 393 |
}
|
| 394 |
|
| 395 |
+
console.log("Inserting into database in chunks...");
|
| 396 |
|
| 397 |
+
const chunkSize = 100;
|
| 398 |
let inserted = 0;
|
| 399 |
|
| 400 |
for (let i = 0; i < mockUsers.length; i += chunkSize) {
|
|
|
|
| 403 |
try {
|
| 404 |
await db.insert(user).values(chunk);
|
| 405 |
inserted += chunk.length;
|
| 406 |
+
console.log(`Inserted ${inserted}/${count}`);
|
| 407 |
} catch (err) {
|
| 408 |
+
console.error("Chunk insert failed:");
|
| 409 |
console.error(JSON.stringify(err, null, 2));
|
| 410 |
}
|
| 411 |
}
|
| 412 |
|
| 413 |
+
console.log(`Done. Total inserted: ${inserted}/${count}`);
|
| 414 |
}
|
| 415 |
|
| 416 |
seedIndianUsers(600)
|
|
|
|
| 419 |
process.exit(0);
|
| 420 |
})
|
| 421 |
.catch((err) => {
|
| 422 |
+
console.error("Fatal error during seeding:", err);
|
| 423 |
process.exit(1);
|
| 424 |
});
|
src/seed/setup.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import postgres from "postgres";
|
| 2 |
-
import "dotenv/config";
|
| 3 |
import { env } from "../config/env";
|
| 4 |
import fs from "fs";
|
| 5 |
import crypto from "crypto";
|
|
|
|
| 6 |
|
| 7 |
const sql = postgres(env.DATABASE_URL!);
|
| 8 |
|
|
|
|
| 1 |
import postgres from "postgres";
|
|
|
|
| 2 |
import { env } from "../config/env";
|
| 3 |
import fs from "fs";
|
| 4 |
import crypto from "crypto";
|
| 5 |
+
import "dotenv/config";
|
| 6 |
|
| 7 |
const sql = postgres(env.DATABASE_URL!);
|
| 8 |
|