DekEn

อัปเดต 2026-09-07

JWT auth & registration

email + password, bcrypt, first-user-is-admin

Email/password registration and login backed by bcrypt password hashing and JSON Web Tokens (JWT) for session state — the base authentication layer every other account feature builds on.

เมื่อไรจึงใช้
  • You're standing up a new deployment and need the very first account
  • You're building a client against POST /auth/register or /auth/login directly
  • You want to understand what a session token contains before debugging a 401
ค่าที่ต้องกรอก
ค่าคำอธิบาย
คำนวณอย่างไร

POST /auth/register bcrypt-hashes the password and stores the user; POST /auth/login verifies it and issues a signed JWT (HS256, AUTH_SECRET_KEY) that the frontend keeps in authStore and attaches to subsequent API calls.

ข้อควรระวัง
noteThe first user ever registered on a deployment is automatically made admin — a one-time bootstrap rule, not something you configure per user.
noteENV=production flips cookies to Secure-only, so setting it locally over plain HTTP silently breaks the session — leave it unset for local dev.
ที่เกี่ยวข้อง