Files
go-gitea.gitea/web_src/js/features/user-auth.ts
Navneet 3ffccb8fe5 Redirect to the only OAuth2 provider when no other login methods and fix various problems (#36901)
Fixes: #36846 

1. When there is only on OAuth2 login method, automatically direct to it
2. Fix legacy problems in code, including:
   * Rename template filename and fix TODO comments
   * Fix legacy variable names
   * Add missing SSPI variable for template
   * Fix unnecessary layout, remove garbage styles
* Only do AppUrl(ROOT_URL) check when it is needed (avoid unnecessary
warnings to end users)

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-04-01 12:50:57 +00:00

28 lines
1.0 KiB
TypeScript

import {checkAppUrl, checkAppUrlScheme} from './common-page.ts';
export function initUserCheckAppUrl() {
if (!document.querySelector('.page-content.user.signin, .page-content.user.signup, .page-content.user.link-account')) return;
checkAppUrlScheme();
}
export function initUserExternalLogins() {
const container = document.querySelector('#external-login-navigator');
if (!container) return;
// whether the auth method requires app url check (need consistent ROOT_URL with visited URL)
let needCheckAppUrl = false;
for (const link of container.querySelectorAll('.external-login-link')) {
needCheckAppUrl = needCheckAppUrl || link.getAttribute('data-require-appurl-check') === 'true';
link.addEventListener('click', () => {
container.classList.add('is-loading');
setTimeout(() => {
// recover previous content to let user try again, usually redirection will be performed before this action
container.classList.remove('is-loading');
}, 5000);
});
}
if (needCheckAppUrl) {
checkAppUrl();
}
}