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.
18 lines
768 B
18 lines
768 B
import type { H3Event } from "h3";
|
|
import { getCurrentUser } from "#server/utils/context";
|
|
import { getTempTokenFromCookie } from "#server/service/agent/temp-token";
|
|
import type { CharacterIdentity } from "./types";
|
|
|
|
/**
|
|
* 解析角色模块的调用方身份(登录用户 或 访客 tempToken)。
|
|
* 复用 agent 的 temp-token 原语:tempToken 本质是"访客身份",
|
|
* agent 与 character 共享同一访客身份,避免重复造一套 cookie 机制。
|
|
*/
|
|
export async function resolveCharacterIdentity(event: H3Event): Promise<CharacterIdentity> {
|
|
const user = await getCurrentUser(event);
|
|
if (user) {
|
|
return { userId: user.id, tempToken: null };
|
|
}
|
|
const tempToken = getTempTokenFromCookie(event);
|
|
return { userId: null, tempToken };
|
|
}
|
|
|