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

Fix login page redirect

This commit is contained in:
Bill Thornton 2023-02-28 15:38:08 -05:00
parent 6190041ef1
commit 84f4e7c991

View file

@ -1,5 +1,5 @@
import React, { FunctionComponent, useEffect, useState } from 'react'; import React, { FunctionComponent, useEffect, useState } from 'react';
import { Outlet, useNavigate } from 'react-router-dom'; import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import type { ConnectResponse } from 'jellyfin-apiclient'; import type { ConnectResponse } from 'jellyfin-apiclient';
import alert from './alert'; import alert from './alert';
@ -31,11 +31,11 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
isUserRequired = true isUserRequired = true
}) => { }) => {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const [ isLoading, setIsLoading ] = useState(true); const [ isLoading, setIsLoading ] = useState(true);
useEffect(() => { useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const bounce = async (connectionResponse: ConnectResponse) => { const bounce = async (connectionResponse: ConnectResponse) => {
switch (connectionResponse.State) { switch (connectionResponse.State) {
case ConnectionState.SignedIn: case ConnectionState.SignedIn:
@ -45,12 +45,12 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
return; return;
case ConnectionState.ServerSignIn: case ConnectionState.ServerSignIn:
// Bounce to the login page // Bounce to the login page
console.debug('[ConnectionRequired] not logged in, redirecting to login page'); if (location.pathname === BounceRoutes.Login) {
navigate(BounceRoutes.Login, { setIsLoading(false);
state: { } else {
serverid: connectionResponse.ApiClient.serverId() console.debug('[ConnectionRequired] not logged in, redirecting to login page');
} navigate(`${BounceRoutes.Login}?serverid=${connectionResponse.ApiClient.serverId()}`);
}); }
return; return;
case ConnectionState.ServerSelection: case ConnectionState.ServerSelection:
// Bounce to select server page // Bounce to select server page
@ -144,7 +144,7 @@ const ConnectionRequired: FunctionComponent<ConnectionRequiredProps> = ({
}; };
validateConnection(); validateConnection();
}, [ isAdminRequired, isUserRequired, navigate ]); }, [ isAdminRequired, isUserRequired, location.pathname, navigate ]);
if (isLoading) { if (isLoading) {
return <Loading />; return <Loading />;