feat(auth): preserve and restore last visited page URL after quota modal or header login (v1.5.10)

This commit is contained in:
Enes Yakıştır
2026-10-03 12:13:15 +03:00
parent aa9c4c76c8
commit f37f42fe40
2 changed files with 52 additions and 5 deletions
+51 -4
View File
@@ -246,7 +246,53 @@ try {
initSilentSSOProbe(); initSilentSSOProbe();
} }
function saveReturnUrlBeforeLogin() {
try {
var currentPath = window.location.pathname + window.location.search + window.location.hash;
if (currentPath && !window.location.pathname.includes('/login')) {
localStorage.setItem('yaktube_return_url', currentPath);
localStorage.setItem('yaktube_return_url_time', String(Date.now()));
sessionStorage.setItem('yaktube_return_url', currentPath);
sessionStorage.setItem('redirect-url-after-login', currentPath);
}
} catch (e) {}
}
function checkPendingPostLoginRedirect() {
try {
if (window.location.pathname.includes('/login')) return false;
var token = localStorage.getItem('access_token');
if (!token) return false;
var savedUrl =
localStorage.getItem('yaktube_return_url') ||
sessionStorage.getItem('yaktube_return_url') ||
sessionStorage.getItem('redirect-url-after-login');
if (!savedUrl) return false;
var savedTime = parseInt(localStorage.getItem('yaktube_return_url_time') || '0', 10);
localStorage.removeItem('yaktube_return_url');
localStorage.removeItem('yaktube_return_url_time');
sessionStorage.removeItem('yaktube_return_url');
sessionStorage.removeItem('redirect-url-after-login');
if (savedTime && Date.now() - savedTime > 15 * 60 * 1000) return false;
var currentFull = window.location.pathname + window.location.search + window.location.hash;
if (
typeof savedUrl === 'string' &&
savedUrl.startsWith('/') &&
!savedUrl.startsWith('//') &&
!savedUrl.startsWith('/login') &&
savedUrl !== currentFull
) {
window.location.replace(savedUrl);
return true;
}
} catch (e) {}
return false;
}
checkPendingPostLoginRedirect();
function triggerYakNetOAuth() { function triggerYakNetOAuth() {
saveReturnUrlBeforeLogin();
sessionStorage.removeItem('yaknet_manual_logout'); sessionStorage.removeItem('yaknet_manual_logout');
var callbackUrl = 'https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback'; var callbackUrl = 'https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback';
window.location.href = window.location.href =
@@ -2966,10 +3012,7 @@ try {
} }
function redirectToPeerTubeLogin() { function redirectToPeerTubeLogin() {
try { saveReturnUrlBeforeLogin();
// Save current URL in sessionStorage just as PeerTube's LoginComponent does
sessionStorage.setItem('redirect-url-after-login', window.location.pathname + window.location.search);
} catch (e) {}
// 1. Check PeerTube's native login link in header (handles redirectOnSingleExternalAuth / YakNet SSO automatically) // 1. Check PeerTube's native login link in header (handles redirectOnSingleExternalAuth / YakNet SSO automatically)
var loginLink = document.querySelector( var loginLink = document.querySelector(
@@ -5146,6 +5189,10 @@ try {
// 10. Unified Debounced MutationObserver & Reactive SPA Engine (v1.5.0) // 10. Unified Debounced MutationObserver & Reactive SPA Engine (v1.5.0)
var unifiedTimer = null; var unifiedTimer = null;
function runUnifiedCycle(isNav) { function runUnifiedCycle(isNav) {
try {
if (checkPendingPostLoginRedirect()) return;
} catch (e) {}
try { try {
autoFixDOM(); autoFixDOM();
} catch (e) {} } catch (e) {}
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-yaktube-ondemand", "name": "peertube-plugin-yaktube-ondemand",
"version": "1.5.9", "version": "1.5.10",
"description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube", "description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube",
"main": "main.js", "main": "main.js",
"library": "./main.js", "library": "./main.js",