Skip to content

Commit b9f57fa

Browse files
authored
Update authentication callback and login URL to include redirect URI based on frontend origin (#2856)
1 parent e22f9f3 commit b9f57fa

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/api/user/auth.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { apiRequest } from '../'
77
export const userAuth = {
88
signOut: async () => await apiRequest.get('auth/signout').json<void>(),
99

10-
callback: async (code: string) =>
11-
await apiRequest.get(`auth/callback?code=${code}`).json<OAuthCallbackResponse>(),
10+
callback: async (code: string) => {
11+
const frontendOrigin = window.env.VITE_APP_URL || window.location.origin
12+
return await apiRequest
13+
.get(`auth/callback?code=${code}&redirect_uri=${encodeURIComponent(frontendOrigin)}`)
14+
.json<OAuthCallbackResponse>()
15+
},
1216

1317
whoAmI: (isLoggedOut: boolean) =>
1418
useQuery(

src/contexts/AuthContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ 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
178179
const oauthBaseUrl = window.env.VITE_SERVER_OAUTH_URL
179-
const loginUrl = `?redirect=${encodeURIComponent(currentUrl)}`
180+
const loginUrl = `?redirect=${encodeURIComponent(currentUrl)}&redirect_uri=${encodeURIComponent(frontendOrigin)}`
180181

181182
try {
182183
const oauthApi = createApiWithBaseUrl(oauthBaseUrl)

0 commit comments

Comments
 (0)