fix(auth): atomically exchange gateway tokens

This commit is contained in:
2026-07-31 18:00:07 +00:00
parent 2596c47fc5
commit c29b40ba5a
4 changed files with 112 additions and 21 deletions
+2 -4
View File
@@ -87,15 +87,13 @@ export const authRouter = router({
await enqueueProfileIconResetForUser(ctx, payload.user.id, payload.user.profileIconResetAt);
}
const used = await ctx.accessTokenStore.markGatewayTokenUsed(payload.sessionId, ttlSeconds);
if (!used) {
const created = await ctx.accessTokenStore.issueFromGateway(payload);
if (created === 'ALREADY_USED') {
throw new TRPCError({
code: 'CONFLICT',
message: 'Gateway token already used.',
});
}
const created = await ctx.accessTokenStore.create(payload);
if (!created) {
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',