MCPcopy Create free account
hub / github.com/tiann/hapi / parseAccessToken

Function parseAccessToken

hub/src/utils/accessToken.ts:8–34  ·  view source on GitHub ↗
(raw: string)

Source from the content-addressed store, hash-verified

6}
7
8export function parseAccessToken(raw: string): ParsedAccessToken | null {
9 if (!raw) {
10 return null
11 }
12
13 const trimmed = raw.trim()
14 if (!trimmed) {
15 return null
16 }
17
18 const separatorIndex = trimmed.lastIndexOf(':')
19 if (separatorIndex === -1) {
20 return { baseToken: trimmed, namespace: DEFAULT_NAMESPACE }
21 }
22
23 const baseToken = trimmed.slice(0, separatorIndex)
24 const namespace = trimmed.slice(separatorIndex + 1)
25 if (!baseToken || !namespace) {
26 return null
27 }
28
29 if (baseToken.trim() !== baseToken || namespace.trim() !== namespace) {
30 return null
31 }
32
33 return { baseToken, namespace }
34}

Callers 5

createSocketServerFunction · 0.90
createBindRoutesFunction · 0.90
createAuthRoutesFunction · 0.90
createCliRoutesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected