diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 762d658..5390525 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -265,11 +265,15 @@ function LoginContent() { } // Poll for authorization - await login(pinId); + const loginResult = await login(pinId); // Close popup authWindow.close(); + if (loginResult === 'profile-selection-required') { + return; + } + // Redirect to intended page or homepage const redirect = searchParams.get('redirect') || '/'; router.push(redirect); diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 298c7be..0fee5ab 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -24,11 +24,13 @@ interface User { permissions?: UserPermissions; } +export type LoginResult = 'authenticated' | 'profile-selection-required'; + interface AuthContextType { user: User | null; accessToken: string | null; isLoading: boolean; - login: (pinId: number) => Promise; + login: (pinId: number) => Promise; logout: () => void; refreshToken: () => Promise; setAuthData: (user: User, accessToken: string) => void; @@ -182,7 +184,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { }; // Poll Plex OAuth callback during login - const login = async (pinId: number) => { + const login = async (pinId: number): Promise => { const maxAttempts = 60; // 2 minutes total let attempts = 0; @@ -211,7 +213,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { // Redirect to profile selection page // Note: Plex token is stored server-side for security, not in sessionStorage window.location.href = data.redirectUrl; - return; + return 'profile-selection-required'; } // Login successful (no profile selection needed) @@ -226,7 +228,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { // Schedule auto-refresh scheduleTokenRefresh(data.accessToken); - return; + return 'authenticated'; } // Still waiting for authorization diff --git a/tests/contexts/AuthContext.test.tsx b/tests/contexts/AuthContext.test.tsx index 72e0bcf..d5054e9 100644 --- a/tests/contexts/AuthContext.test.tsx +++ b/tests/contexts/AuthContext.test.tsx @@ -20,13 +20,15 @@ vi.mock('@/lib/utils/jwt-client', () => ({ function TestConsumer() { const { user, accessToken, isLoading, login, logout, refreshToken, setAuthData } = useAuth(); + const [loginResult, setLoginResult] = React.useState('none'); return (
{String(isLoading)}
{user?.username ?? 'none'}
{accessToken ?? 'none'}
-