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

Function createCliSession

freebuff/web/src/app/onboard/_db.ts:129–175  ·  view source on GitHub ↗
(
  userId: string,
  fingerprintId: string,
  fingerprintHash: string,
  sessionToken?: string,
)

Source from the content-addressed store, hash-verified

127}
128
129export async function createCliSession(
130 userId: string,
131 fingerprintId: string,
132 fingerprintHash: string,
133 sessionToken?: string,
134): Promise<boolean> {
135 return db.transaction(async (tx: DbTransaction) => {
136 await tx
137 .insert(schema.fingerprint)
138 .values({ id: fingerprintId })
139 .onConflictDoNothing()
140
141 const session = await tx
142 .insert(schema.session)
143 .values({
144 sessionToken: crypto.randomUUID(),
145 userId,
146 expires: MAX_DATE,
147 fingerprint_id: fingerprintId,
148 cli_auth_hash: fingerprintHash,
149 type: 'cli',
150 })
151 .onConflictDoNothing()
152 .returning({ userId: schema.session.userId })
153
154 if (sessionToken) {
155 await tx
156 .update(schema.session)
157 .set({ fingerprint_id: fingerprintId })
158 .where(
159 and(
160 eq(schema.session.sessionToken, sessionToken),
161 eq(schema.session.userId, userId),
162 isNull(schema.session.fingerprint_id),
163 eq(schema.session.type, 'web'),
164 ),
165 )
166 } else {
167 logger.warn(
168 { fingerprintId, userId },
169 'No session token found, cannot link web session to fingerprint',
170 )
171 }
172
173 return session.length > 0
174 })
175}

Callers 1

OnboardFunction · 0.90

Calls 2

insertMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected