Next.js 14 + Drizzle/PostgreSQL + SSE realtime sync — highlight, freehand, comment, bookmark + ฟีเจอร์ต่อยอด F1–F19 (edit/move, undo/redo, shapes, redaction, export PDF/CSV, reply, resolve, search, summary, textbox, stamp, version history) Co-Authored-By: Claude Code <noreply@anthropic.com>
25 lines
1 KiB
TypeScript
25 lines
1 KiB
TypeScript
// anonymous identity เก็บใน localStorage สร้างครั้งเดียวต่อ browser (PLAN.md §0 A4)
|
|
// ใช้เติม field userId/userName ในตาราง annotations/bookmarks — ไม่มีระบบ auth
|
|
|
|
export type LocalUser = { userId: string; userName: string };
|
|
|
|
const STORAGE_KEY = "judes-note:user";
|
|
|
|
export function getLocalUser(): LocalUser {
|
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
if (raw) {
|
|
try {
|
|
const parsed = JSON.parse(raw) as LocalUser;
|
|
if (typeof parsed.userId === "string" && typeof parsed.userName === "string") {
|
|
return parsed;
|
|
}
|
|
} catch {
|
|
// ข้อมูลเก่าเสียหาย → สร้างใหม่ต่อด้านล่าง
|
|
}
|
|
}
|
|
|
|
const userId = crypto.randomUUID();
|
|
const userName = `ผู้ใช้ ${userId.slice(0, 4).toUpperCase()}`;
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({ userId, userName }));
|
|
return { userId, userName };
|
|
}
|