fix(auth): prevent duplicate plex callback requests
React re-renders caused useEffect to fire twice. First request succeeded, second consumed already-used PIN → 500. Added useRef guard to dedupe.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { authApi } from "@/lib/api";
|
||||
import { useStore } from "@/lib/store";
|
||||
@@ -11,8 +11,12 @@ export default function AuthCallbackPage() {
|
||||
const router = useRouter();
|
||||
const { setUser, setToken } = useStore();
|
||||
const [status, setStatus] = useState("Completing sign in...");
|
||||
const hasRun = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (hasRun.current) return;
|
||||
hasRun.current = true;
|
||||
|
||||
const pinId = sessionStorage.getItem("plexPinId");
|
||||
|
||||
if (!pinId) {
|
||||
|
||||
Reference in New Issue
Block a user