2026-09-22 18:54:34 +03:00
|
|
|
async function register({ registerHook, peertubeHelpers }) {
|
2026-09-06 11:35:45 +03:00
|
|
|
try {
|
2026-09-06 11:37:57 +03:00
|
|
|
fetch('/plugins/auth-yaknet/router/status')
|
2026-09-06 11:35:45 +03:00
|
|
|
.then(function (r) {
|
|
|
|
|
return r.json();
|
|
|
|
|
})
|
|
|
|
|
.then(function (status) {
|
|
|
|
|
if (!status || status.autoRedirectLogin === false) {
|
|
|
|
|
return; // Auto redirect is disabled by administrator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isLoginUrl = window.location.pathname.includes('/login');
|
|
|
|
|
var isLocal = window.location.search.includes('local=true');
|
|
|
|
|
var isError = window.location.search.includes('externalAuthError');
|
|
|
|
|
|
|
|
|
|
// If user directly visits /login without local override or error, forward to YakNet SSO
|
|
|
|
|
if (isLoginUrl && !isLocal && !isError) {
|
2026-09-06 11:37:57 +03:00
|
|
|
window.location.replace('/plugins/auth-yaknet/router/auth');
|
2026-09-06 11:35:45 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Intercept clicks on login links/buttons
|
|
|
|
|
document.addEventListener(
|
|
|
|
|
'click',
|
|
|
|
|
function (e) {
|
|
|
|
|
var el = e.target;
|
|
|
|
|
if (el && el.closest) {
|
|
|
|
|
var isLoginBtn = el.closest(
|
|
|
|
|
'my-login-link, .login-button, a[href*="/login"]:not(#yaktube-show-admin-login), a[aria-label*="Giriş"], a[title*="Giriş"], a[title*="login"], a[aria-label*="login"]'
|
|
|
|
|
);
|
|
|
|
|
if (isLoginBtn && !window.location.search.includes('local=true')) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
2026-09-06 11:37:57 +03:00
|
|
|
window.location.href = '/plugins/auth-yaknet/router/auth';
|
2026-09-06 11:35:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.catch(function () {});
|
|
|
|
|
|
|
|
|
|
// Alt+A shortcut for local admin login bypass
|
|
|
|
|
document.addEventListener('keydown', function (e) {
|
|
|
|
|
if (e.altKey && (e.key === 'a' || e.key === 'A')) {
|
|
|
|
|
if (!window.location.pathname.includes('/login')) {
|
|
|
|
|
window.location.href = '/login?local=true';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.warn('[YakNet SSO] Client init error:', err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 18:54:34 +03:00
|
|
|
export { register, register as registerClient };
|
|
|
|
|
export default register;
|