fix: use authFetch for Todoist OAuth connect to send auth header
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 6s

This commit is contained in:
Play Life Bot
2026-01-02 15:40:06 +03:00
parent 72002a2b4f
commit 713f6020f6
2 changed files with 29 additions and 5 deletions

View File

@@ -5927,8 +5927,13 @@ func (a *App) todoistOAuthConnectHandler(w http.ResponseWriter, r *http.Request)
url.QueryEscape(redirectURI),
)
log.Printf("Todoist OAuth: redirecting user_id=%d to Todoist", userID)
http.Redirect(w, r, authURL, http.StatusTemporaryRedirect)
log.Printf("Todoist OAuth: returning auth URL for user_id=%d", userID)
// Возвращаем JSON с URL для редиректа (frontend сделает редирект)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
"auth_url": authURL,
})
}
// todoistOAuthCallbackHandler обрабатывает OAuth callback

View File

@@ -50,9 +50,28 @@ function TodoistIntegration({ onBack }) {
}
}
const handleConnect = () => {
// Перенаправляем на OAuth endpoint
window.location.href = '/api/integrations/todoist/oauth/connect'
const handleConnect = async () => {
try {
setLoading(true)
setError('')
// Получаем URL для редиректа через авторизованный запрос
const response = await authFetch('/api/integrations/todoist/oauth/connect')
if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
throw new Error(errorData.error || 'Ошибка при подключении Todoist')
}
const data = await response.json()
if (data.auth_url) {
// Делаем редирект на Todoist OAuth
window.location.href = data.auth_url
} else {
throw new Error('URL для авторизации не получен')
}
} catch (error) {
console.error('Error connecting Todoist:', error)
setError(error.message || 'Не удалось подключить Todoist')
setLoading(false)
}
}
const handleDisconnect = async () => {