login.post.mjs
1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { e as eventHandler, r as readBody, a as authenticateMockUser, c as createMockSession, t as toPublicUser } from '../../../nitro/nitro.mjs';
import { z } from 'zod';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '@iconify/utils';
import 'consola';
const loginPayloadSchema = z.object({
username: z.string().trim().min(1),
password: z.string().trim().min(1)
});
const login_post = eventHandler(async (event) => {
const body = await readBody(event);
const parsed = loginPayloadSchema.safeParse(body);
if (!parsed.success) {
return {
success: false,
state: "failed",
nextAction: "retry",
errorCode: "VALIDATION_ERROR",
message: "\u7528\u6237\u540D\u548C\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A\u3002"
};
}
const user = authenticateMockUser(parsed.data.username, parsed.data.password);
if (!user) {
return {
success: false,
state: "failed",
nextAction: "retry",
errorCode: "INVALID_CREDENTIALS",
message: "\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF\u3002"
};
}
const session = createMockSession(user.username);
return {
success: true,
state: "authenticated",
nextAction: "enter_dashboard",
errorCode: null,
message: "\u767B\u5F55\u6210\u529F\u3002",
token: session.token,
expiresAt: new Date(session.expiresAt).toISOString(),
user: toPublicUser(user)
};
});
export { login_post as default };
//# sourceMappingURL=login.post.mjs.map