@@ -21,6 +21,10 @@ export interface SetupAuthServerOptions {
2121 authServerUrl : URL ;
2222 mcpServerUrl : URL ;
2323 strictResource ?: boolean ;
24+ /**
25+ * Examples should be used for **demo** only and not for production purposes, however this mode disables some logging and other features.
26+ */
27+ demoMode : boolean ;
2428}
2529
2630// Store auth instance globally so it can be used for token verification
@@ -75,13 +79,14 @@ async function ensureDemoUserExists(auth: DemoAuth): Promise<void> {
7579 * @param options - Server configuration
7680 */
7781export function setupAuthServer ( options : SetupAuthServerOptions ) : void {
78- const { authServerUrl, mcpServerUrl } = options ;
82+ const { authServerUrl, mcpServerUrl, demoMode } = options ;
7983
8084 // Create better-auth instance with MCP plugin
8185 const auth = createDemoAuth ( {
8286 baseURL : authServerUrl . toString ( ) . replace ( / \/ $ / , '' ) ,
8387 resource : mcpServerUrl . toString ( ) ,
84- loginPage : '/sign-in'
88+ loginPage : '/sign-in' ,
89+ demoMode : demoMode
8590 } ) ;
8691
8792 // Store globally for token verification
@@ -111,23 +116,25 @@ export function setupAuthServer(options: SetupAuthServerOptions): void {
111116 console . log ( `${ timestamp } [Auth Request] Content-Type: ${ req . headers [ 'content-type' ] } ` ) ;
112117 }
113118
114- // Log response when it finishes
115- const originalSend = res . send . bind ( res ) ;
116- res . send = function ( body ) {
117- console . log ( `${ timestamp } [Auth Response] ${ res . statusCode } ${ req . url } ` ) ;
118- if ( res . statusCode >= 400 && body ) {
119- try {
120- const parsed = typeof body === 'string' ? JSON . parse ( body ) : body ;
121- console . log ( `${ timestamp } [Auth Response] Error:` , parsed ) ;
122- } catch {
123- // Not JSON, log as-is if short
124- if ( typeof body === 'string' && body . length < 200 ) {
125- console . log ( `${ timestamp } [Auth Response] Body: ${ body } ` ) ;
119+ if ( demoMode ) {
120+ // Log response when it finishes
121+ const originalSend = res . send . bind ( res ) ;
122+ res . send = function ( body ) {
123+ console . log ( `${ timestamp } [Auth Response] ${ res . statusCode } ${ req . url } ` ) ;
124+ if ( res . statusCode >= 400 && body ) {
125+ try {
126+ const parsed = typeof body === 'string' ? JSON . parse ( body ) : body ;
127+ console . log ( `${ timestamp } [Auth Response] Error:` , parsed ) ;
128+ } catch {
129+ // Not JSON, log as-is if short
130+ if ( typeof body === 'string' && body . length < 200 ) {
131+ console . log ( `${ timestamp } [Auth Response] Body: ${ body } ` ) ;
132+ }
126133 }
127134 }
128- }
129- return originalSend ( body ) ;
130- } ;
135+ return originalSend ( body ) ;
136+ } ;
137+ }
131138 next ( ) ;
132139 } ) ;
133140
@@ -137,7 +144,6 @@ export function setupAuthServer(options: SetupAuthServerOptions): void {
137144
138145 // OAuth metadata endpoints using better-auth's built-in handlers
139146 authApp . get ( '/.well-known/oauth-authorization-server' , toNodeHandler ( oAuthDiscoveryMetadata ( auth ) ) ) ;
140- authApp . get ( '/.well-known/oauth-protected-resource' , toNodeHandler ( oAuthProtectedResourceMetadata ( auth ) ) ) ;
141147
142148 // Body parsers for non-better-auth routes (like /sign-in)
143149 authApp . use ( express . json ( ) ) ;
0 commit comments