@@ -4,7 +4,7 @@ import axios from 'axios'
44import * as crypto from 'node:crypto'
55import { BuiltinRoutePath } from '../Routes/routePath'
66import { IInternalServerManager } from '../../types/internal'
7- import { CLOUD_BASE_URL } from '../utils'
7+ import { API_BASE_URL , CLOUD_BASE_URL } from '../utils'
88import { exchangeToken , generatePkceVerifier , isErrorResponse , pkceChallengeFromVerifier } from './utils'
99import type { ILocalesKey } from '../../i18n/zh-CN'
1010
@@ -228,14 +228,17 @@ class AuthHandler {
228228
229229 const verifier = this . pkceVerifier
230230 if ( ! verifier ) {
231+ this . ctx . log . error ( 'PKCE verifier is missing during callback handling' )
231232 const message = this . ctx . i18n . translate < ILocalesKey > ( 'CLOUD_LOGIN_EXCHANGE_FAILED' )
232233 this . abortPendingLogin ( pending , message )
233234 return c . html ( this . renderResultPage ( false , message ) , 500 )
234235 }
235236
236237 try {
238+ this . ctx . log . info ( 'API_BASE_URL' , API_BASE_URL , 'Exchanging login code for token...' )
237239 const exchange = await exchangeToken ( code , verifier )
238240 if ( ! exchange . token ) {
241+ this . ctx . log . error ( 'Token exchange failed without throwing an error' )
239242 const message = exchange . message ?? this . ctx . i18n . translate < ILocalesKey > ( 'CLOUD_LOGIN_EXCHANGE_FAILED' )
240243 this . abortPendingLogin ( pending , message )
241244 return c . html ( this . renderResultPage ( false , message ) , 500 )
@@ -272,6 +275,7 @@ class AuthHandler {
272275 const finalMessage = message ?? fallback
273276 const finalStatus = status === 400 ? 400 : 500
274277 this . abortPendingLogin ( pending , finalMessage )
278+ this . ctx . log . error ( `Token exchange failed: ${ finalMessage } (status: ${ finalStatus } )` , error )
275279 return c . html ( this . renderResultPage ( false , finalMessage ) , finalStatus )
276280 }
277281 }
0 commit comments