Skip to content

Commit c521343

Browse files
committed
fix: use structured reason discriminant instead of fragile string comparison in credential consume flow
Replace exact message string comparison with a 'reason' discriminant field on the ConsumeResult error variant ('not-found' | 'expired') to determine whether to fall through from in-memory seeded grants to the database-backed pairing link lookup. This prevents the database lookup from silently breaking if the error message text is ever changed.
1 parent f8cec10 commit c521343

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/server/src/auth/Layers/BootstrapCredentialService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface StoredBootstrapGrant extends BootstrapGrant {
2121
type ConsumeResult =
2222
| {
2323
readonly _tag: "error";
24+
readonly reason: "not-found" | "expired";
2425
readonly error: BootstrapCredentialError;
2526
}
2627
| {
@@ -178,6 +179,7 @@ export const makeBootstrapCredentialService = Effect.gen(function* () {
178179
return [
179180
{
180181
_tag: "error",
182+
reason: "not-found",
181183
error: invalidBootstrapCredentialError("Unknown bootstrap credential."),
182184
},
183185
current,
@@ -190,6 +192,7 @@ export const makeBootstrapCredentialService = Effect.gen(function* () {
190192
return [
191193
{
192194
_tag: "error",
195+
reason: "expired",
193196
error: invalidBootstrapCredentialError("Bootstrap credential expired."),
194197
},
195198
next,
@@ -227,7 +230,7 @@ export const makeBootstrapCredentialService = Effect.gen(function* () {
227230
if (seededResult._tag === "success") {
228231
return seededResult.grant;
229232
}
230-
if (seededResult.error.message !== "Unknown bootstrap credential.") {
233+
if (seededResult.reason !== "not-found") {
231234
return yield* seededResult.error;
232235
}
233236

0 commit comments

Comments
 (0)