MCPcopy Create free account
hub / github.com/MemTensor/MemOS / issueUserToken

Function issueUserToken

packages/memos-core/src/hub/auth.ts:48–56  ·  view source on GitHub ↗
(
  payload: { userId: string; username: string; role: UserRole; status: UserStatus },
  secret: string,
  ttlMs = 24 * 60 * 60 * 1000,
)

Source from the content-addressed store, hash-verified

46}
47
48export function issueUserToken(
49 payload: { userId: string; username: string; role: UserRole; status: UserStatus },
50 secret: string,
51 ttlMs = 24 * 60 * 60 * 1000,
52): string {
53 const full: UserTokenPayload = { ...payload, exp: Date.now() + ttlMs };
54 const body = base64url(JSON.stringify(full));
55 return `${body}.${sign(body, secret)}`;
56}
57
58export function verifyUserToken(token: string, secret: string): Omit<UserTokenPayload, "exp"> | null {
59 const idx = token.lastIndexOf(".");

Callers 2

ensureBootstrapAdminMethod · 0.90
handleMethod · 0.90

Calls 2

base64urlFunction · 0.70
signFunction · 0.70

Tested by

no test coverage detected