Revert "Fix the double callback call resulting in the Auth code already used screen"
This reverts commit 0f79b1d753.
This commit is contained in:
parent
0f79b1d753
commit
2924a5d52d
1 changed files with 14 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useEffect, useState, Suspense } from "react"
|
import { useEffect, useState, useRef, Suspense } from "react"
|
||||||
import { useRouter, useSearchParams } from "next/navigation"
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
@ -14,21 +14,17 @@ function AuthCallbackContent() {
|
||||||
const [status, setStatus] = useState<"processing" | "success" | "error">("processing")
|
const [status, setStatus] = useState<"processing" | "success" | "error">("processing")
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [purpose, setPurpose] = useState<string>("app_auth")
|
const [purpose, setPurpose] = useState<string>("app_auth")
|
||||||
|
const hasProcessed = useRef(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const code = searchParams.get('code')
|
// Prevent double execution in React Strict Mode
|
||||||
const callbackKey = `callback_processed_${code}`
|
if (hasProcessed.current) return
|
||||||
|
hasProcessed.current = true
|
||||||
// Prevent double execution across component remounts
|
|
||||||
if (sessionStorage.getItem(callbackKey)) {
|
|
||||||
console.log('Callback already processed, skipping')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sessionStorage.setItem(callbackKey, 'true')
|
|
||||||
|
|
||||||
const handleCallback = async () => {
|
const handleCallback = async () => {
|
||||||
try {
|
try {
|
||||||
// Get parameters from URL
|
// Get parameters from URL
|
||||||
|
const code = searchParams.get('code')
|
||||||
const state = searchParams.get('state')
|
const state = searchParams.get('state')
|
||||||
const errorParam = searchParams.get('error')
|
const errorParam = searchParams.get('error')
|
||||||
|
|
||||||
|
|
@ -41,6 +37,14 @@ function AuthCallbackContent() {
|
||||||
const detectedPurpose = authPurpose || (storedConnectorType?.includes('drive') ? 'data_source' : 'app_auth')
|
const detectedPurpose = authPurpose || (storedConnectorType?.includes('drive') ? 'data_source' : 'app_auth')
|
||||||
setPurpose(detectedPurpose)
|
setPurpose(detectedPurpose)
|
||||||
|
|
||||||
|
// Debug logging
|
||||||
|
console.log('OAuth Callback Debug:', {
|
||||||
|
urlParams: { code: !!code, state: !!state, error: errorParam },
|
||||||
|
localStorage: { connectorId, storedConnectorType, authPurpose },
|
||||||
|
detectedPurpose,
|
||||||
|
fullUrl: window.location.href
|
||||||
|
})
|
||||||
|
|
||||||
// Use state parameter as connection_id if localStorage is missing
|
// Use state parameter as connection_id if localStorage is missing
|
||||||
const finalConnectorId = connectorId || state
|
const finalConnectorId = connectorId || state
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue