From 713f6020f66b8e8b6a35465d25a06ee2dc945d48 Mon Sep 17 00:00:00 2001 From: Play Life Bot Date: Fri, 2 Jan 2026 15:40:06 +0300 Subject: [PATCH] fix: use authFetch for Todoist OAuth connect to send auth header --- play-life-backend/main.go | 9 +++++-- .../src/components/TodoistIntegration.jsx | 25 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/play-life-backend/main.go b/play-life-backend/main.go index 2ab1373..abcb802 100644 --- a/play-life-backend/main.go +++ b/play-life-backend/main.go @@ -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 diff --git a/play-life-web/src/components/TodoistIntegration.jsx b/play-life-web/src/components/TodoistIntegration.jsx index 291f139..77985b1 100644 --- a/play-life-web/src/components/TodoistIntegration.jsx +++ b/play-life-web/src/components/TodoistIntegration.jsx @@ -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 () => {