Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/app/api/auth/raindrop/callback/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export async function GET(request) {

if (!tokenResponse.ok) {
const errorData = await tokenResponse.text()
console.error('Token exchange failed:', errorData)
console.error('Token exchange failed:', {
status: tokenResponse.status,
statusText: tokenResponse.statusText,
headers: Object.fromEntries(tokenResponse.headers.entries()),
errorData
})
throw new Error(`Token exchange failed: ${tokenResponse.status}`)
}

Expand All @@ -74,11 +79,13 @@ export async function GET(request) {

// 存储令牌
const tokenManager = getTokenManager()
await tokenManager.storeInitialTokens(
const storeResult = await tokenManager.storeInitialTokens(
tokenData.access_token,
tokenData.refresh_token,
tokenData.expires_in || 1209600 // 默认14天
)

console.info('Token storage result:', storeResult)

// 验证令牌是否工作
const testResponse = await fetch(`${RAINDROP_API_URL}/user`, {
Expand Down
19 changes: 13 additions & 6 deletions src/lib/auth/env-token-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export class EnvTokenManager {

async storeTokenInfo(tokenInfo) {
try {
encrypt(JSON.stringify(tokenInfo))

// 在这种实现中,我们只能输出加密后的token,需要手动添加到环境变量
// 注意:在生产环境中,应该通过其他方式传递这个信息

return true
const encryptedToken = encrypt(JSON.stringify(tokenInfo))

console.info('✅ Token encrypted successfully!')
console.info('🔐 Encrypted token (add this to RAINDROP_ENCRYPTED_REFRESH_TOKEN env var):')
console.info(encryptedToken)

return encryptedToken
} catch (error) {
console.error('Failed to encrypt token for storage:', error)
return false
Expand Down Expand Up @@ -122,6 +123,12 @@ export class EnvTokenManager {
updatedAt: Date.now()
}

console.info('Storing initial tokens:', {
hasAccessToken: !!accessToken,
hasRefreshToken: !!refreshToken,
expiresIn
})

return await this.storeTokenInfo(tokenInfo)
}
}
Expand Down
Loading