You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
611 B
22 lines
611 B
import { loginUser } from "#server/service/auth";
|
|
import { toPublicAuthError } from "#server/service/auth/errors";
|
|
import { setSessionCookie } from "#server/service/auth/cookie";
|
|
|
|
type LoginBody = {
|
|
username: string;
|
|
password: string;
|
|
};
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
try {
|
|
const body = await readBody<LoginBody>(event);
|
|
const result = await loginUser(body);
|
|
setSessionCookie(event, result.sessionId);
|
|
|
|
return R.success({
|
|
user: result.user,
|
|
});
|
|
} catch (err) {
|
|
throw toPublicAuthError(err);
|
|
}
|
|
});
|
|
|