Skip to content

Commit d39ab0c

Browse files
authored
Remove OAuth URL references from environment files and refactor authentication logic to use shared API request client. (#2863)
1 parent b9f57fa commit d39ab0c

5 files changed

Lines changed: 7 additions & 16 deletions

File tree

.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ VITE_APP_NAME="MapRoulette"
22
VITE_APP_DESCRIPTION="MapRoulette 4 Local Development Environment"
33
VITE_API_BASE_URL="https://maproulette.org"
44
VITE_MAP_ROULETTE_SERVER_WEBSOCKET_URL="wss://maproulette.org/ws"
5-
VITE_SERVER_OAUTH_URL="https://maproulette.org/auth/authenticate"
65
VITE_SERVER_API_KEY=""
76
# Base URL for short links embedded in OSM changeset comments
87
# (e.g. https://mpr.lt/c/<challengeId>/t/<taskId>). If unset,

.env.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ VITE_APP_URL="http://localhost:3005"
44

55
VITE_API_BASE_URL="http://localhost:9000"
66
VITE_MAP_ROULETTE_SERVER_WEBSOCKET_URL="ws://localhost:9000/ws"
7-
VITE_SERVER_OAUTH_URL="http://localhost:9000/auth/authenticate"
87

98
# Must match MR_SUPER_KEY in docker-compose.test.yaml.
109
VITE_SERVER_API_KEY="super-secret-key"

src/api/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ export const apiRequest = ky.extend({
4747
},
4848
})
4949

50-
export const createApiWithBaseUrl = (baseUrl: string) => {
51-
return apiRequest.extend({
52-
prefixUrl: baseUrl,
53-
})
54-
}
55-
5650
export const convertParamsToSearchParams = (
5751
params: Record<
5852
string,

src/contexts/AuthContext.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQueryClient } from '@tanstack/react-query'
22
import { useLocation, useSearch } from '@tanstack/react-router'
33
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'
4-
import { api, createApiWithBaseUrl } from '@/api'
4+
import { api, apiRequest } from '@/api'
55
import { Loader } from '@/components/ui/Loader'
66
import { logger } from '@/lib/logger'
77
import type { OAuthLoginResponse } from '@/types/Oauth'
@@ -175,13 +175,13 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
175175
const currentUrl = location.pathname + location.searchStr
176176
setStoredRedirectUrl(currentUrl)
177177

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-
182178
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')
185185
const jsonData = (await response.json()) as OAuthLoginResponse
186186

187187
if (jsonData.state) {

src/vite-env.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface AppEnv {
1212
readonly VITE_APP_DESCRIPTION: string
1313
readonly VITE_API_BASE_URL: string | undefined
1414
readonly VITE_MAP_ROULETTE_SERVER_WEBSOCKET_URL: string
15-
readonly VITE_SERVER_OAUTH_URL: string
1615
readonly VITE_SERVER_API_KEY: string | undefined
1716
readonly VITE_GITHUB_ISSUES_API_OWNER: string | undefined
1817
readonly VITE_GITHUB_ISSUES_API_REPO: string | undefined

0 commit comments

Comments
 (0)