@@ -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" ;
2427import { AuthControlPlaneLive , AuthCoreLive } from "./AuthControlPlane.ts" ;
2528
2629type BootstrapExchangeResult = {
@@ -31,24 +34,6 @@ type BootstrapExchangeResult = {
3134const AUTHORIZATION_PREFIX = "Bearer " ;
3235const 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-
5237export 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