1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Add support for redirecting to the requested page after login

This commit is contained in:
Bill Thornton 2024-01-18 16:30:36 -05:00
parent bb77009f44
commit d88bcb48d7
2 changed files with 24 additions and 13 deletions

View file

@ -47,8 +47,9 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
if (location.pathname === BounceRoutes.Login) {
setIsLoading(false);
} else {
console.debug('[ConnectionRequired] not logged in, redirecting to login page');
navigate(`${BounceRoutes.Login}?serverid=${connectionResponse.ApiClient.serverId()}`);
console.debug('[ConnectionRequired] not logged in, redirecting to login page', location);
const url = encodeURIComponent(location.pathname + location.search);
navigate(`${BounceRoutes.Login}?serverid=${connectionResponse.ApiClient.serverId()}&url=${url}`);
}
return;
case ConnectionState.ServerSelection:

View file

@ -20,13 +20,13 @@ import { getDefaultBackgroundClass } from '../../../components/cardbuilder/cardB
const enableFocusTransform = !browser.slow && !browser.edge;
function authenticateUserByName(page, apiClient, username, password) {
function authenticateUserByName(page, apiClient, url, username, password) {
loading.show();
apiClient.authenticateUserByName(username, password).then(function (result) {
const user = result.User;
loading.hide();
onLoginSuccessful(user.Id, result.AccessToken, apiClient);
onLoginSuccessful(user.Id, result.AccessToken, apiClient, url);
}, function (response) {
page.querySelector('#txtManualPassword').value = '';
loading.hide();
@ -44,7 +44,7 @@ function authenticateUserByName(page, apiClient, username, password) {
});
}
function authenticateQuickConnect(apiClient) {
function authenticateQuickConnect(apiClient, targetUrl) {
const url = apiClient.getUrl('/QuickConnect/Initiate');
apiClient.ajax({ type: 'POST', url }, true).then(res => res.json()).then(function (json) {
if (!json.Secret || !json.Code) {
@ -77,7 +77,7 @@ function authenticateQuickConnect(apiClient) {
}
const result = await apiClient.quickConnect(data.Secret);
onLoginSuccessful(result.User.Id, result.AccessToken, apiClient);
onLoginSuccessful(result.User.Id, result.AccessToken, apiClient, targetUrl);
}, function (e) {
clearInterval(interval);
@ -108,9 +108,9 @@ function authenticateQuickConnect(apiClient) {
});
}
function onLoginSuccessful(id, accessToken, apiClient) {
function onLoginSuccessful(id, accessToken, apiClient, url) {
Dashboard.onServerChanged(id, accessToken, apiClient);
Dashboard.navigate('home.html');
Dashboard.navigate(url || 'home.html');
}
function showManualForm(context, showCancel, focusPassword) {
@ -192,6 +192,18 @@ export default function (view, params) {
return ApiClient;
}
function getTargetUrl() {
if (params.url) {
try {
return decodeURIComponent(params.url);
} catch (err) {
console.warn('[LoginPage] unable to decode url param', params.url, err);
}
}
return '/home.html';
}
function showVisualForm() {
view.querySelector('.visualLoginForm').classList.remove('hide');
view.querySelector('.manualLoginForm').classList.add('hide');
@ -216,7 +228,7 @@ export default function (view, params) {
context.querySelector('#txtManualName').value = '';
showManualForm(context, true);
} else if (haspw == 'false') {
authenticateUserByName(context, getApiClient(), name, '');
authenticateUserByName(context, getApiClient(), getTargetUrl(), name, '');
} else {
context.querySelector('#txtManualName').value = name;
context.querySelector('#txtManualPassword').value = '';
@ -226,8 +238,7 @@ export default function (view, params) {
});
view.querySelector('.manualLoginForm').addEventListener('submit', function (e) {
appSettings.enableAutoLogin(view.querySelector('.chkRememberLogin').checked);
const apiClient = getApiClient();
authenticateUserByName(view, apiClient, view.querySelector('#txtManualName').value, view.querySelector('#txtManualPassword').value);
authenticateUserByName(view, getApiClient(), getTargetUrl(), view.querySelector('#txtManualName').value, view.querySelector('#txtManualPassword').value);
e.preventDefault();
return false;
});
@ -236,8 +247,7 @@ export default function (view, params) {
});
view.querySelector('.btnCancel').addEventListener('click', showVisualForm);
view.querySelector('.btnQuick').addEventListener('click', function () {
const apiClient = getApiClient();
authenticateQuickConnect(apiClient);
authenticateQuickConnect(getApiClient(), getTargetUrl());
return false;
});
view.querySelector('.btnManual').addEventListener('click', function () {