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
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 6s
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user