MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseAuthCode

Function parseAuthCode

web/src/app/onboard/_helpers.ts:107–142  ·  view source on GitHub ↗
(authCode: string)

Source from the content-addressed store, hash-verified

105}
106
107export function parseAuthCode(authCode: string): {
108 fingerprintId: string
109 expiresAt: string
110 receivedHash: string
111} {
112 const normalizedAuthCode = authCode.trim()
113 const hashSeparatorIndex = normalizedAuthCode.lastIndexOf('.')
114 const expiresSeparatorIndex = normalizedAuthCode.lastIndexOf(
115 '.',
116 hashSeparatorIndex - 1,
117 )
118
119 if (hashSeparatorIndex === -1 || expiresSeparatorIndex === -1) {
120 const legacyMatch = normalizedAuthCode.match(
121 /^(?<fingerprintId>.+)-(?<expiresAt>\d+)-(?<receivedHash>[a-f0-9]{64})$/i,
122 )
123 if (legacyMatch?.groups) {
124 return {
125 fingerprintId: legacyMatch.groups.fingerprintId,
126 expiresAt: legacyMatch.groups.expiresAt,
127 receivedHash: legacyMatch.groups.receivedHash,
128 }
129 }
130
131 return { fingerprintId: '', expiresAt: '', receivedHash: '' }
132 }
133
134 const fingerprintId = normalizedAuthCode.slice(0, expiresSeparatorIndex)
135 const expiresAt = normalizedAuthCode.slice(
136 expiresSeparatorIndex + 1,
137 hashSeparatorIndex,
138 )
139 const receivedHash = normalizedAuthCode.slice(hashSeparatorIndex + 1)
140
141 return { fingerprintId, expiresAt, receivedHash }
142}
143
144export function validateAuthCode(
145 receivedHash: string,

Callers 3

OnboardFunction · 0.90
helpers.test.tsFile · 0.90
LoginPageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected