|
1 | 1 | import { useQueryClient } from '@tanstack/react-query' |
2 | 2 | import { useLocation, useSearch } from '@tanstack/react-router' |
3 | 3 | import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react' |
4 | | -import { api, createApiWithBaseUrl } from '@/api' |
| 4 | +import { api, apiRequest } from '@/api' |
5 | 5 | import { Loader } from '@/components/ui/Loader' |
6 | 6 | import { logger } from '@/lib/logger' |
7 | 7 | import type { OAuthLoginResponse } from '@/types/Oauth' |
@@ -175,13 +175,13 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { |
175 | 175 | const currentUrl = location.pathname + location.searchStr |
176 | 176 | setStoredRedirectUrl(currentUrl) |
177 | 177 |
|
178 | | - const frontendOrigin = window.env.VITE_APP_URL || window.location.origin |
179 | | - const oauthBaseUrl = window.env.VITE_SERVER_OAUTH_URL |
180 | | - const loginUrl = `?redirect=${encodeURIComponent(currentUrl)}&redirect_uri=${encodeURIComponent(frontendOrigin)}` |
181 | | - |
182 | 178 | try { |
183 | | - const oauthApi = createApiWithBaseUrl(oauthBaseUrl) |
184 | | - const response = await oauthApi.get(loginUrl) |
| 179 | + // Hit the backend via the shared apiRequest client (same host as the |
| 180 | + // callback) so the backend derives the OAuth redirect_uri from this |
| 181 | + // request's Origin header, which resolves correctly across deployments |
| 182 | + // (maproulette.org, beta.maproulette.org, 127.0.0.1). No redirect param: |
| 183 | + // post-login navigation is handled client-side via the stored redirect URL. |
| 184 | + const response = await apiRequest.get('auth/authenticate') |
185 | 185 | const jsonData = (await response.json()) as OAuthLoginResponse |
186 | 186 |
|
187 | 187 | if (jsonData.state) { |
|
0 commit comments