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.
14 lines
522 B
14 lines
522 B
import { toPublicAuthError } from "#server/service/auth/errors";
|
|
|
|
/**
|
|
* 客户端对齐用:无会话 Cookie 时不访问数据库;有 Cookie 时与 SSR `auth.getCurrent()` 同路径。
|
|
* 始终 200 + `{ user }`,不向未登录客户端抛 401(与 `/api/auth/me` 区分)。
|
|
*/
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
try {
|
|
const user = await event.context.auth.getCurrent();
|
|
return R.success({ user: user ?? null });
|
|
} catch (err) {
|
|
throw toPublicAuthError(err);
|
|
}
|
|
});
|
|
|