Skip to content

Commit 1c0b8ec

Browse files
Use credential error messages in auth logging
- Log `SessionCredentialError.message` directly when session auth fails - Remove redundant auth failure reason helper
1 parent 6068555 commit 1c0b8ec

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import {
2020
AuthError,
2121
type ServerAuthShape,
2222
} from "../Services/ServerAuth.ts";
23-
import { SessionCredentialService } from "../Services/SessionCredentialService.ts";
23+
import {
24+
SessionCredentialError,
25+
SessionCredentialService,
26+
} from "../Services/SessionCredentialService.ts";
2427
import { AuthControlPlaneLive, AuthCoreLive } from "./AuthControlPlane.ts";
2528

2629
type BootstrapExchangeResult = {
@@ -31,24 +34,6 @@ type BootstrapExchangeResult = {
3134
const AUTHORIZATION_PREFIX = "Bearer ";
3235
const WEBSOCKET_TOKEN_QUERY_PARAM = "wsToken";
3336

34-
function authFailureReason(cause: unknown): string {
35-
if (cause instanceof Error && cause.message.trim().length > 0) {
36-
return cause.message;
37-
}
38-
39-
if (
40-
typeof cause === "object" &&
41-
cause !== null &&
42-
"message" in cause &&
43-
typeof cause.message === "string" &&
44-
cause.message.trim().length > 0
45-
) {
46-
return cause.message;
47-
}
48-
49-
return "unknown";
50-
}
51-
5237
export function toBootstrapExchangeAuthError(cause: BootstrapCredentialError): AuthError {
5338
if (cause.status === 500) {
5439
return new AuthError({
@@ -83,10 +68,10 @@ export const makeServerAuth = Effect.gen(function* () {
8368

8469
const authenticateToken = (token: string): Effect.Effect<AuthenticatedSession, AuthError> =>
8570
sessions.verify(token).pipe(
86-
Effect.tapError((cause) =>
71+
Effect.tapError((cause: SessionCredentialError) =>
8772
Effect.logWarning("Rejected authenticated session credential.").pipe(
8873
Effect.annotateLogs({
89-
reason: authFailureReason(cause),
74+
reason: cause.message,
9075
}),
9176
),
9277
),

0 commit comments

Comments
 (0)