account management upgrades
This commit is contained in:
parent
94de501a49
commit
86fdd403b0
8 changed files with 439 additions and 46 deletions
|
|
@ -9,14 +9,14 @@ export async function POST(req: NextRequest) {
|
|||
try {
|
||||
const body = await req.json().catch(() => ({} as any));
|
||||
const identifier = String(body?.identifier ?? "").trim();
|
||||
const password = String(body?.password ?? "").trim();
|
||||
const password = String(body?.password ?? "").trim();
|
||||
|
||||
if (!identifier || !password) {
|
||||
return NextResponse.json({ error: "Missing credentials" }, { status: 400 });
|
||||
}
|
||||
|
||||
// Resolve identifier -> email (username allowed)
|
||||
let email = identifier.includes("@") ? identifier : await emailForUsername(identifier);
|
||||
// Resolve identifier -> email (username or email accepted)
|
||||
const email = identifier.includes("@") ? identifier : await emailForUsername(identifier);
|
||||
if (!email) return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
|
||||
const auth = await loginDirectus(email, password);
|
||||
|
|
@ -30,7 +30,8 @@ export async function POST(req: NextRequest) {
|
|||
const res = NextResponse.json({ ok: true });
|
||||
|
||||
// Refresh the access token cookie
|
||||
const maxAge = typeof expiresSec === "number" ? Math.max(0, Math.floor(expiresSec)) : 60 * 60 * 8;
|
||||
const maxAge =
|
||||
typeof expiresSec === "number" ? Math.max(0, Math.floor(expiresSec)) : 60 * 60 * 8;
|
||||
res.cookies.set({
|
||||
name: "ma_at",
|
||||
value: access,
|
||||
|
|
@ -41,7 +42,7 @@ export async function POST(req: NextRequest) {
|
|||
maxAge,
|
||||
});
|
||||
|
||||
// Short-lived client-visible flag: “recently authenticated”
|
||||
// Short-lived client-visible flag: “recently authenticated” (5 minutes)
|
||||
res.cookies.set({
|
||||
name: "ma_ra",
|
||||
value: "1",
|
||||
|
|
@ -49,7 +50,7 @@ export async function POST(req: NextRequest) {
|
|||
sameSite: "lax",
|
||||
secure,
|
||||
path: "/",
|
||||
maxAge: 5 * 60, // 5 minutes
|
||||
maxAge: 5 * 60,
|
||||
});
|
||||
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue