Skip to content

Commit 1b076ae

Browse files
committed
📦 Chore: add logs for login
1 parent 98ce098 commit 1b076ae

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/lib/Cloud/Auth.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import axios from 'axios'
44
import * as crypto from 'node:crypto'
55
import { BuiltinRoutePath } from '../Routes/routePath'
66
import { IInternalServerManager } from '../../types/internal'
7-
import { CLOUD_BASE_URL } from '../utils'
7+
import { API_BASE_URL, CLOUD_BASE_URL } from '../utils'
88
import { exchangeToken, generatePkceVerifier, isErrorResponse, pkceChallengeFromVerifier } from './utils'
99
import 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
}

src/lib/Server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class ServerManager implements IServerManager {
221221
}
222222

223223
if (!token || token !== this.authSecret) {
224+
this.ctx.log.warn(`[PicGo Server] Unauthorized request to ${method} ${path} with token from ${source}`)
224225
this.logUnauthorized(c)
225226
return c.json({ success: false, message: 'Unauthorized' }, 401)
226227
}

0 commit comments

Comments
 (0)