fix(setup): fix Plex login not proceeding after authentication#2596
fix(setup): fix Plex login not proceeding after authentication#2596fallenbagel wants to merge 2 commits intodevelopfrom
Conversation
Align SetupLogin Plex auth handling with `LoginWithPlex` by checking `response.data.id` instead of re`sponse.data.email a`nd directly populating the SWR cache to bypass disabled automatic revalidation on setup pages. fix #2585
📝 WalkthroughWalkthroughWrapped Plex auth POST in try/catch, changed success check to response.data?.id, fetches current user from GET /api/v1/auth/me on success, and calls revalidate(user, false); errors are handled silently to allow retries without UI disruption. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (browser)
participant API as Server `/api/v1/auth/plex`
participant Me as Server `/api/v1/auth/me`
participant Reval as revalidate()
Client->>API: POST /api/v1/auth/plex (credentials)
alt POST succeeds and returns id
API-->>Client: 200 { id, ... }
Client->>Me: GET /api/v1/auth/me
Me-->>Client: 200 { user }
Client->>Reval: revalidate(user, false)
Reval-->>Client: UI updated
else POST fails or throws
API-->>Client: error
Client->>Client: catch error (silent)
Client-->>Client: allow user to retry
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes the setup wizard getting stuck after successful Plex OAuth by using a more reliable success signal and explicitly populating the authenticated user into SWR cache so the setup flow can advance without requiring an automatic revalidation.
Changes:
- Switch Plex auth success check from
response.data?.emailtoresponse.data?.id. - After Plex auth, fetch
/api/v1/auth/meand inject the user into SWR viarevalidate(user, false)to avoid relying on disabled auto-revalidation.
Comments suppressed due to low confidence (2)
src/components/Setup/SetupLogin.tsx:52
login()performs two awaited requests (/api/v1/auth/plexthen/api/v1/auth/me) but there’s no try/catch around them. If either call fails, the promise rejection fromlogin()will be unhandled and the setup wizard can remain stuck with no feedback. Consider wrapping the body in try/catch and surfacing the error (or resettingauthTokento allow retry) so failures don’t silently block progression.
const login = async () => {
const response = await axios.post('/api/v1/auth/plex', {
authToken: authToken,
});
if (response.data?.id) {
const { data: user } = await axios.get('/api/v1/auth/me');
revalidate(user, false);
}
};
src/components/Setup/SetupLogin.tsx:50
- The
const { data: user } = await axios.get('/api/v1/auth/me');local variable name shadows theuserfromuseUser(), which makes the flow harder to follow. Renaming the response (e.g.,me/currentUser) and typing the request (e.g.,axios.get<User>(...)) would improve readability and keep this from becomingany.
const { data: user } = await axios.get('/api/v1/auth/me');
revalidate(user, false);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/Setup/SetupLogin.tsx`:
- Around line 48-50: Wrap the axios.get('/api/v1/auth/me') call in a try/catch
inside SetupLogin.tsx so failures don't leave setup stuck: inside the existing
if (response.data?.id) block, try to fetch const { data: user } = await
axios.get('/api/v1/auth/me') and call revalidate(user, false) on success; in the
catch log the error and call revalidate(null, false) (or another safe fallback)
so the setup flow can continue even if the /api/v1/auth/me request fails.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
src/components/Setup/SetupLogin.tsx:50
- The
login()effect can throw (either the/auth/plexPOST or the new/auth/meGET), and becauselogin()is invoked withoutawait/.catch()insideuseEffect, any failure becomes an unhandled promise rejection and leaves the setup flow stuck. Please wrap the body in atry/catch(and handle/reset state or show a toast) or calllogin().catch(...)to handle errors explicitly.
const login = async () => {
const response = await axios.post('/api/v1/auth/plex', {
authToken: authToken,
});
if (response.data?.id) {
const { data: user } = await axios.get('/api/v1/auth/me');
revalidate(user, false);
src/components/Setup/SetupLogin.tsx:50
- The
const { data: user } = await axios.get('/api/v1/auth/me')shadows the outeruserfromuseUser(), which makes the effect harder to read and increases the chance of accidentally using the wrong variable. Consider renaming the fetched value to something likefetchedUser/meto avoid shadowing.
const { data: user } = await axios.get('/api/v1/auth/me');
revalidate(user, false);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
♻️ Duplicate comments (2)
src/components/Setup/SetupLogin.tsx (1)
50-55:⚠️ Potential issue | 🟠 MajorHandle
/api/v1/auth/mefailure with a fallback path.If Line 50 fails, Line 53 swallows the error and user state is never updated, so setup can still stall. Add a fallback recovery step in this branch.
Suggested hardening
- try { - const response = await axios.post('/api/v1/auth/plex', { - authToken: authToken, - }); - - if (response.data?.id) { - const { data: user } = await axios.get('/api/v1/auth/me'); - revalidate(user, false); - } - } catch { - // auth failed silently and user can attempt again - } + try { + const response = await axios.post('/api/v1/auth/plex', { authToken }); + if (!response.data?.id) { + return; + } + + try { + const { data: user } = await axios.get('/api/v1/auth/me'); + await revalidate(user, false); + } catch { + await revalidate(); + } + } catch { + // auth failed silently and user can attempt again + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Setup/SetupLogin.tsx` around lines 50 - 55, The catch block for the axios.get('/api/v1/auth/me') call in SetupLogin.tsx currently swallows errors and never updates user state; change the catch to capture the error, log it, and trigger a fallback revalidation so setup can continue (for example call revalidate(null, true) or otherwise set the unauthenticated/fallback state), and optionally surface a retryable UI flag; update the catch to accept (err) and call console.error(err) (or the app logger) and revalidate(null, true) so the app does not stall.src/components/Setup/LoginWithPlex.tsx (1)
31-36:⚠️ Potential issue | 🟠 MajorAdd recovery behavior when
/api/v1/auth/mefails.When Line 31 throws, Line 34 silently exits and the flow may remain stuck without advancing. Add a fallback revalidation/retry path in this catch branch too.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Setup/LoginWithPlex.tsx` around lines 31 - 36, When the axios.get('/api/v1/auth/me') call fails, the catch currently swallows the error and leaves the flow stalled; update the catch block to perform a recovery revalidation and a retry trigger by calling the existing revalidate(...) helper with a fallback value (e.g., revalidate(null, true) or revalidate(undefined, true)) and optionally schedule a short retry of axios.get('/api/v1/auth/me') (using setTimeout) so the UI advances and the auth flow can recover; reference axios.get('/api/v1/auth/me') and the revalidate function to implement this behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/components/Setup/LoginWithPlex.tsx`:
- Around line 31-36: When the axios.get('/api/v1/auth/me') call fails, the catch
currently swallows the error and leaves the flow stalled; update the catch block
to perform a recovery revalidation and a retry trigger by calling the existing
revalidate(...) helper with a fallback value (e.g., revalidate(null, true) or
revalidate(undefined, true)) and optionally schedule a short retry of
axios.get('/api/v1/auth/me') (using setTimeout) so the UI advances and the auth
flow can recover; reference axios.get('/api/v1/auth/me') and the revalidate
function to implement this behavior.
In `@src/components/Setup/SetupLogin.tsx`:
- Around line 50-55: The catch block for the axios.get('/api/v1/auth/me') call
in SetupLogin.tsx currently swallows errors and never updates user state; change
the catch to capture the error, log it, and trigger a fallback revalidation so
setup can continue (for example call revalidate(null, true) or otherwise set the
unauthenticated/fallback state), and optionally surface a retryable UI flag;
update the catch to accept (err) and call console.error(err) (or the app logger)
and revalidate(null, true) so the app does not stall.
Description
During initial setup, after completing Plex OAuth, the wizard gets stuck on step 2 and requires a manual page reload to proceed.
This is because the auth effect checks
response.data?.email to determine if login succeeded, but the Plex auth endpoint doesn't return an email, sorevalidate()never gets called. The login page correctly checks .id instead. Also when revalidation is triggered, a barerevalidate()relies on SWR to refetch/api/v1/auth/mein the background, butuseUserdisables all automatic revalidation on setup pages, making this unreliable.The PR adds a fix to explicitly fetch the user after auth and injects it directly into the SWR cache with
revalidate(user, false). This should match the pattern used in the login page.How Has This Been Tested?
Screenshots / Logs (if applicable)
Checklist:
pnpm buildpnpm i18n:extractSummary by CodeRabbit