Skip to content

Commit 4e5f654

Browse files
committed
Enhance Plex authentication flow and user redirection
- Updated the user.js file to include a setup_mode flag in the Plex link request, aligning it with the existing setup implementation. - Refined login.html to ensure consistent redirection behavior after successful login and Plex PIN creation. - Modified plex_auth_routes.py to return a redirect URL in the response for successful Plex login and account linking, improving user experience during authentication.
1 parent 1995cfc commit 4e5f654

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

frontend/static/js/user.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,15 @@ class UserModule {
371371
document.getElementById('plexLinkStatus').textContent = 'Linking account...';
372372

373373
try {
374+
// Use the same approach as setup - let backend get username from database
374375
const linkResponse = await fetch('./api/auth/plex/link', {
375376
method: 'POST',
376377
headers: {
377378
'Content-Type': 'application/json'
378379
},
379380
body: JSON.stringify({
380-
token: result.token
381+
token: result.token,
382+
setup_mode: true // Use setup mode like the working implementation
381383
})
382384
});
383385

frontend/templates/login.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ <h2>Account Recovery</h2>
617617

618618
if (status === 200 && body.success) {
619619
// Login successful
620-
window.location.href = body.redirect || './';
620+
window.location.href = body.redirect || './';
621621
} else if (status === 401 && requires2FA) {
622622
// 2FA is required
623623
console.log('2FA required, showing 2FA input field');
@@ -734,8 +734,8 @@ <h2>Account Recovery</h2>
734734
setPlexStatus('waiting', '<i class="fas fa-spinner spinner"></i> Creating Plex PIN...');
735735

736736
// Create Plex PIN
737-
HuntarrUtils.fetchWithTimeout('./api/auth/plex/pin', {
738-
method: 'POST',
737+
HuntarrUtils.fetchWithTimeout('./api/auth/plex/pin', {
738+
method: 'POST',
739739
headers: {
740740
'Content-Type': 'application/json',
741741
},
@@ -855,7 +855,7 @@ <h2>Account Recovery</h2>
855855
if (data.success) {
856856
setPlexStatus('success', '<i class="fas fa-check"></i> Login successful! Redirecting...');
857857
setTimeout(() => {
858-
window.location.href = './';
858+
window.location.href = data.redirect || './';
859859
}, 1500);
860860
} else {
861861
if (status === 409) {

src/primary/routes/plex_auth_routes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ def handle_oauth_callback():
195195
return jsonify({
196196
'success': True,
197197
'message': 'Login successful',
198-
'user': plex_user_data
198+
'user': plex_user_data,
199+
'redirect': './'
199200
})
200201
else:
201202
return jsonify({
@@ -246,7 +247,8 @@ def plex_login():
246247
response = jsonify({
247248
'success': True,
248249
'message': 'Plex user created and logged in successfully',
249-
'auth_type': 'plex'
250+
'auth_type': 'plex',
251+
'redirect': './'
250252
})
251253
session[SESSION_COOKIE_NAME] = session_id # Store in Flask session
252254
response.set_cookie(SESSION_COOKIE_NAME, session_id,
@@ -277,7 +279,8 @@ def plex_login():
277279
response = jsonify({
278280
'success': True,
279281
'message': 'Logged in with Plex successfully',
280-
'auth_type': 'plex'
282+
'auth_type': 'plex',
283+
'redirect': './'
281284
})
282285
session[SESSION_COOKIE_NAME] = session_id # Store in Flask session
283286
response.set_cookie(SESSION_COOKIE_NAME, session_id,

0 commit comments

Comments
 (0)