diff --git a/frontend/static/js/user.js b/frontend/static/js/user.js index 3930999f..65f045d0 100644 --- a/frontend/static/js/user.js +++ b/frontend/static/js/user.js @@ -371,13 +371,15 @@ class UserModule { document.getElementById('plexLinkStatus').textContent = 'Linking account...'; try { + // Use the same approach as setup - let backend get username from database const linkResponse = await fetch('./api/auth/plex/link', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - token: result.token + token: result.token, + setup_mode: true // Use setup mode like the working implementation }) }); diff --git a/frontend/templates/login.html b/frontend/templates/login.html index f153a654..4cc4f949 100644 --- a/frontend/templates/login.html +++ b/frontend/templates/login.html @@ -617,7 +617,7 @@ if (status === 200 && body.success) { // Login successful - window.location.href = body.redirect || './'; + window.location.href = body.redirect || './'; } else if (status === 401 && requires2FA) { // 2FA is required console.log('2FA required, showing 2FA input field'); @@ -734,8 +734,8 @@ setPlexStatus('waiting', ' Creating Plex PIN...'); // Create Plex PIN - HuntarrUtils.fetchWithTimeout('./api/auth/plex/pin', { - method: 'POST', + HuntarrUtils.fetchWithTimeout('./api/auth/plex/pin', { + method: 'POST', headers: { 'Content-Type': 'application/json', }, @@ -855,7 +855,7 @@ if (data.success) { setPlexStatus('success', ' Login successful! Redirecting...'); setTimeout(() => { - window.location.href = './'; + window.location.href = data.redirect || './'; }, 1500); } else { if (status === 409) { diff --git a/src/primary/routes/plex_auth_routes.py b/src/primary/routes/plex_auth_routes.py index 930a6bc3..0d393e8a 100644 --- a/src/primary/routes/plex_auth_routes.py +++ b/src/primary/routes/plex_auth_routes.py @@ -195,7 +195,8 @@ def handle_oauth_callback(): return jsonify({ 'success': True, 'message': 'Login successful', - 'user': plex_user_data + 'user': plex_user_data, + 'redirect': './' }) else: return jsonify({ @@ -246,7 +247,8 @@ def plex_login(): response = jsonify({ 'success': True, 'message': 'Plex user created and logged in successfully', - 'auth_type': 'plex' + 'auth_type': 'plex', + 'redirect': './' }) session[SESSION_COOKIE_NAME] = session_id # Store in Flask session response.set_cookie(SESSION_COOKIE_NAME, session_id, @@ -277,7 +279,8 @@ def plex_login(): response = jsonify({ 'success': True, 'message': 'Logged in with Plex successfully', - 'auth_type': 'plex' + 'auth_type': 'plex', + 'redirect': './' }) session[SESSION_COOKIE_NAME] = session_id # Store in Flask session response.set_cookie(SESSION_COOKIE_NAME, session_id,