WeMWish commited on
Commit
580e3ba
·
1 Parent(s): 596296c

Fix OAuth infinite redirect loop

Browse files

The problem: Button observer was firing on each page load, even during OAuth callback
- When page reloads with ?code=xxx, it's a new session
- once=TRUE resets, so observer fires again
- This triggered another OAuth redirect, creating infinite loop

The fix:
- Check URL query string for 'code' parameter in button observer
- If code exists, skip redirect (we're in callback)
- Also skip showing login overlay if code is in URL
- This prevents the loop: code in URL → skip button → process auth → done

Now the flow works:
1. Click Sign in → redirect to HF OAuth
2. HF redirects back with ?code=xxx
3. Button observer sees code in URL, doesn't fire
4. JavaScript sends code to server
5. Server processes auth → hides overlay → shows user info

Files changed (1) hide show
  1. server.R +16 -1
server.R CHANGED
@@ -169,6 +169,13 @@ if 'agents.manager_agent' in sys.modules:
169
  observeEvent(input$hfSignInBtn, {
170
  req(input$hfSignInBtn)
171
 
 
 
 
 
 
 
 
172
  if (!oauth_config$enabled) {
173
  print("OAuth: Not enabled")
174
  return()
@@ -203,8 +210,16 @@ if 'agents.manager_agent' in sys.modules:
203
  }, ignoreInit = TRUE, once = TRUE)
204
 
205
  # Send initial auth state on session start
 
206
  observe({
207
- session$sendCustomMessage('auth_state', list(authenticated = FALSE))
 
 
 
 
 
 
 
208
  })
209
 
210
  # OAuth callback handler
 
169
  observeEvent(input$hfSignInBtn, {
170
  req(input$hfSignInBtn)
171
 
172
+ # Check if we're in OAuth callback (code in URL)
173
+ query_string <- parseQueryString(session$clientData$url_search)
174
+ if (!is.null(query_string$code)) {
175
+ print("OAuth: In callback, skipping button redirect")
176
+ return()
177
+ }
178
+
179
  if (!oauth_config$enabled) {
180
  print("OAuth: Not enabled")
181
  return()
 
210
  }, ignoreInit = TRUE, once = TRUE)
211
 
212
  # Send initial auth state on session start
213
+ # Don't send if we're in OAuth callback (will be handled after auth completes)
214
  observe({
215
+ isolate({
216
+ # Check if we're in OAuth callback by looking at URL parameters
217
+ query_string <- parseQueryString(session$clientData$url_search)
218
+ if (is.null(query_string$code)) {
219
+ # No OAuth code in URL, show login overlay
220
+ session$sendCustomMessage('auth_state', list(authenticated = FALSE))
221
+ }
222
+ })
223
  })
224
 
225
  # OAuth callback handler