Merge pull request #168 from langflow-ai/fix-auth-callback-double-execution
Fix double OAuth callback execution using sessionStorage
This commit is contained in:
commit
6df204d324
1 changed files with 9 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useEffect, useState, useRef, Suspense } from "react"
|
import { useEffect, useState, 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,17 +14,20 @@ 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(() => {
|
||||||
// Prevent double execution in React Strict Mode
|
const code = searchParams.get('code')
|
||||||
if (hasProcessed.current) return
|
const callbackKey = `callback_processed_${code}`
|
||||||
hasProcessed.current = true
|
|
||||||
|
// Prevent double execution across component remounts
|
||||||
|
if (sessionStorage.getItem(callbackKey)) {
|
||||||
|
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')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue