fix: login page not working
This commit is contained in:
8 files changed
+76
-143
No files matched your search
@@ -85,7 +85,7 @@ export const AppBar = () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
enabled: display,
|
||||
enabled: display && Boolean(api),
|
||||
throwOnError: true,
|
||||
});
|
||||
const libraries = useQuery({
|
||||
|
||||
@@ -63,7 +63,7 @@ const AudioPlayer = () => {
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
enabled: Boolean(display),
|
||||
enabled: Boolean(display) && Boolean(api),
|
||||
});
|
||||
|
||||
const waveSurferRef = useRef(null);
|
||||
|
||||
+43
-40
@@ -14,9 +14,9 @@ import { Route as rootRoute } from './routes/__root'
|
||||
import { Route as ApiImport } from './routes/_api'
|
||||
import { Route as IndexImport } from './routes/index'
|
||||
import { Route as ErrorCodeImport } from './routes/error/$code'
|
||||
import { Route as ApiLoginImport } from './routes/_api/login'
|
||||
import { Route as ApiSearchIndexImport } from './routes/_api/search/index'
|
||||
import { Route as ApiPlayerIndexImport } from './routes/_api/player/index'
|
||||
import { Route as ApiLoginIndexImport } from './routes/_api/login/index'
|
||||
import { Route as ApiHomeIndexImport } from './routes/_api/home/index'
|
||||
import { Route as ApiFavoriteIndexImport } from './routes/_api/favorite/index'
|
||||
import { Route as SetupServerListImport } from './routes/setup/server.list'
|
||||
@@ -52,6 +52,11 @@ const ErrorCodeRoute = ErrorCodeImport.update({
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const ApiLoginRoute = ApiLoginImport.update({
|
||||
path: '/login',
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiSearchIndexRoute = ApiSearchIndexImport.update({
|
||||
path: '/search/',
|
||||
getParentRoute: () => ApiRoute,
|
||||
@@ -62,11 +67,6 @@ const ApiPlayerIndexRoute = ApiPlayerIndexImport.update({
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiLoginIndexRoute = ApiLoginIndexImport.update({
|
||||
path: '/login/',
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiHomeIndexRoute = ApiHomeIndexImport.update({
|
||||
path: '/home/',
|
||||
getParentRoute: () => ApiRoute,
|
||||
@@ -108,13 +108,13 @@ const ApiPersonIdRoute = ApiPersonIdImport.update({
|
||||
} as any)
|
||||
|
||||
const ApiLoginManualRoute = ApiLoginManualImport.update({
|
||||
path: '/login/manual',
|
||||
getParentRoute: () => ApiRoute,
|
||||
path: '/manual',
|
||||
getParentRoute: () => ApiLoginRoute,
|
||||
} as any)
|
||||
|
||||
const ApiLoginListRoute = ApiLoginListImport.update({
|
||||
path: '/login/list',
|
||||
getParentRoute: () => ApiRoute,
|
||||
path: '/list',
|
||||
getParentRoute: () => ApiLoginRoute,
|
||||
} as any)
|
||||
|
||||
const ApiLibraryIdRoute = ApiLibraryIdImport.update({
|
||||
@@ -148,8 +148,8 @@ const ApiAlbumIdRoute = ApiAlbumIdImport.update({
|
||||
} as any)
|
||||
|
||||
const ApiLoginUserIdUserNameRoute = ApiLoginUserIdUserNameImport.update({
|
||||
path: '/login/$userId/$userName',
|
||||
getParentRoute: () => ApiRoute,
|
||||
path: '/$userId/$userName',
|
||||
getParentRoute: () => ApiLoginRoute,
|
||||
} as any)
|
||||
|
||||
// Populate the FileRoutesByPath interface
|
||||
@@ -170,6 +170,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof ApiImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/_api/login': {
|
||||
id: '/_api/login'
|
||||
path: '/login'
|
||||
fullPath: '/login'
|
||||
preLoaderRoute: typeof ApiLoginImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/error/$code': {
|
||||
id: '/error/$code'
|
||||
path: '/error/$code'
|
||||
@@ -221,17 +228,17 @@ declare module '@tanstack/react-router' {
|
||||
}
|
||||
'/_api/login/list': {
|
||||
id: '/_api/login/list'
|
||||
path: '/login/list'
|
||||
path: '/list'
|
||||
fullPath: '/login/list'
|
||||
preLoaderRoute: typeof ApiLoginListImport
|
||||
parentRoute: typeof ApiImport
|
||||
parentRoute: typeof ApiLoginImport
|
||||
}
|
||||
'/_api/login/manual': {
|
||||
id: '/_api/login/manual'
|
||||
path: '/login/manual'
|
||||
path: '/manual'
|
||||
fullPath: '/login/manual'
|
||||
preLoaderRoute: typeof ApiLoginManualImport
|
||||
parentRoute: typeof ApiImport
|
||||
parentRoute: typeof ApiLoginImport
|
||||
}
|
||||
'/_api/person/$id': {
|
||||
id: '/_api/person/$id'
|
||||
@@ -289,13 +296,6 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof ApiHomeIndexImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/login/': {
|
||||
id: '/_api/login/'
|
||||
path: '/login'
|
||||
fullPath: '/login'
|
||||
preLoaderRoute: typeof ApiLoginIndexImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/player/': {
|
||||
id: '/_api/player/'
|
||||
path: '/player'
|
||||
@@ -312,10 +312,10 @@ declare module '@tanstack/react-router' {
|
||||
}
|
||||
'/_api/login/$userId/$userName': {
|
||||
id: '/_api/login/$userId/$userName'
|
||||
path: '/login/$userId/$userName'
|
||||
path: '/$userId/$userName'
|
||||
fullPath: '/login/$userId/$userName'
|
||||
preLoaderRoute: typeof ApiLoginUserIdUserNameImport
|
||||
parentRoute: typeof ApiImport
|
||||
parentRoute: typeof ApiLoginImport
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,23 +325,24 @@ declare module '@tanstack/react-router' {
|
||||
export const routeTree = rootRoute.addChildren({
|
||||
IndexRoute,
|
||||
ApiRoute: ApiRoute.addChildren({
|
||||
ApiLoginRoute: ApiLoginRoute.addChildren({
|
||||
ApiLoginListRoute,
|
||||
ApiLoginManualRoute,
|
||||
ApiLoginUserIdUserNameRoute,
|
||||
}),
|
||||
ApiAlbumIdRoute,
|
||||
ApiArtistIdRoute,
|
||||
ApiBoxsetIdRoute,
|
||||
ApiEpisodeIdRoute,
|
||||
ApiItemIdRoute,
|
||||
ApiLibraryIdRoute,
|
||||
ApiLoginListRoute,
|
||||
ApiLoginManualRoute,
|
||||
ApiPersonIdRoute,
|
||||
ApiPlaylistIdRoute,
|
||||
ApiSeriesIdRoute,
|
||||
ApiFavoriteIndexRoute,
|
||||
ApiHomeIndexRoute,
|
||||
ApiLoginIndexRoute,
|
||||
ApiPlayerIndexRoute,
|
||||
ApiSearchIndexRoute,
|
||||
ApiLoginUserIdUserNameRoute,
|
||||
}),
|
||||
ErrorCodeRoute,
|
||||
SetupServerAddRoute,
|
||||
@@ -371,22 +372,28 @@ export const routeTree = rootRoute.addChildren({
|
||||
"/_api": {
|
||||
"filePath": "_api.tsx",
|
||||
"children": [
|
||||
"/_api/login",
|
||||
"/_api/album/$id",
|
||||
"/_api/artist/$id",
|
||||
"/_api/boxset/$id",
|
||||
"/_api/episode/$id",
|
||||
"/_api/item/$id",
|
||||
"/_api/library/$id",
|
||||
"/_api/login/list",
|
||||
"/_api/login/manual",
|
||||
"/_api/person/$id",
|
||||
"/_api/playlist/$id",
|
||||
"/_api/series/$id",
|
||||
"/_api/favorite/",
|
||||
"/_api/home/",
|
||||
"/_api/login/",
|
||||
"/_api/player/",
|
||||
"/_api/search/",
|
||||
"/_api/search/"
|
||||
]
|
||||
},
|
||||
"/_api/login": {
|
||||
"filePath": "_api/login.tsx",
|
||||
"parent": "/_api",
|
||||
"children": [
|
||||
"/_api/login/list",
|
||||
"/_api/login/manual",
|
||||
"/_api/login/$userId/$userName"
|
||||
]
|
||||
},
|
||||
@@ -419,11 +426,11 @@ export const routeTree = rootRoute.addChildren({
|
||||
},
|
||||
"/_api/login/list": {
|
||||
"filePath": "_api/login/list.tsx",
|
||||
"parent": "/_api"
|
||||
"parent": "/_api/login"
|
||||
},
|
||||
"/_api/login/manual": {
|
||||
"filePath": "_api/login/manual.tsx",
|
||||
"parent": "/_api"
|
||||
"parent": "/_api/login"
|
||||
},
|
||||
"/_api/person/$id": {
|
||||
"filePath": "_api/person/$id.tsx",
|
||||
@@ -454,10 +461,6 @@ export const routeTree = rootRoute.addChildren({
|
||||
"filePath": "_api/home/index.tsx",
|
||||
"parent": "/_api"
|
||||
},
|
||||
"/_api/login/": {
|
||||
"filePath": "_api/login/index.tsx",
|
||||
"parent": "/_api"
|
||||
},
|
||||
"/_api/player/": {
|
||||
"filePath": "_api/player/index.tsx",
|
||||
"parent": "/_api"
|
||||
@@ -468,7 +471,7 @@ export const routeTree = rootRoute.addChildren({
|
||||
},
|
||||
"/_api/login/$userId/$userName": {
|
||||
"filePath": "_api/login/$userId.$userName.tsx",
|
||||
"parent": "/_api"
|
||||
"parent": "/_api/login"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_api/login")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
if (location.pathname === "/login") {
|
||||
const api = context.api;
|
||||
console.log(api);
|
||||
const publicUsers = (await getUserApi(api).getPublicUsers()).data;
|
||||
if (publicUsers.length > 0) {
|
||||
throw redirect({ to: "/login/list" });
|
||||
}
|
||||
throw redirect({ to: "/login/manual" });
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -84,7 +84,7 @@ function LoginUser() {
|
||||
await saveUser(userName, user.data.AccessToken);
|
||||
}
|
||||
setLoading(false);
|
||||
navigate("/home");
|
||||
navigate({ to: "/home" });
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { Typography } from "@mui/material";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useLocation, useNavigate } from "@tanstack/react-router";
|
||||
import React, { Suspense, useState } from "react";
|
||||
|
||||
import "./login.scss";
|
||||
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import Markdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/")({
|
||||
component: LoginRoute,
|
||||
});
|
||||
|
||||
function LoginRoute() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const api = Route.useRouteContext().api;
|
||||
const [status, setStatus] = useState("Fetching public users...");
|
||||
|
||||
const usersList = useQuery({
|
||||
queryKey: ["public-users"],
|
||||
queryFn: async () => {
|
||||
const result = await getUserApi(api).getPublicUsers();
|
||||
return result.data;
|
||||
},
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
|
||||
if (location.pathname === "/login") {
|
||||
console.log(api);
|
||||
if (usersList.isSuccess && !usersList.isFetching) {
|
||||
if (usersList.data.length > 0) {
|
||||
setStatus("Public users found!");
|
||||
navigate({ to: "/login/list" });
|
||||
} else {
|
||||
setStatus("No public users found");
|
||||
navigate({ to: "/login/manual" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Suspense fallback={<h1>Loading /login</h1>}>
|
||||
<div
|
||||
style={{
|
||||
position: "relative",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexDirection: "column",
|
||||
width: "100vw",
|
||||
height: "100vh",
|
||||
}}
|
||||
>
|
||||
<CircularProgress size={72} thickness={2} />
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={status}
|
||||
initial={{
|
||||
opacity: 0,
|
||||
transform: "translateY(10px)",
|
||||
}}
|
||||
layout
|
||||
animate={{ opacity: 1, transform: "translateY(0px)" }}
|
||||
exit={{
|
||||
opacity: 0,
|
||||
transform: "translateY(-10px)",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
component={Markdown}
|
||||
remarkPlugins={[remarkGfm]}
|
||||
color="white"
|
||||
variant="h6"
|
||||
mt={3}
|
||||
fontWeight={350}
|
||||
textAlign="center"
|
||||
>
|
||||
{status}
|
||||
</Typography>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
@@ -40,11 +40,6 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/list")({
|
||||
component: LoginPublicUsersList,
|
||||
loader: async ({context}) => {
|
||||
const api = context.api;
|
||||
const result = await getUserApi(api).getPublicUsers();
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
|
||||
function LoginPublicUsersList() {
|
||||
@@ -70,7 +65,14 @@ function LoginPublicUsersList() {
|
||||
const handleManualLogin = () => {
|
||||
// navigate("/login/manual");
|
||||
};
|
||||
const users = Route.useLoaderData();
|
||||
const users = useQuery({
|
||||
queryKey: ["login", "public-users"],
|
||||
queryFn: async () => {
|
||||
const result = await getUserApi(api).getPublicUsers();
|
||||
return result.data;
|
||||
},
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
|
||||
const handleQuickConnect = async () => {
|
||||
setQuickConnectLoading(0);
|
||||
@@ -218,7 +220,10 @@ function LoginPublicUsersList() {
|
||||
itemType="User"
|
||||
cardType="square"
|
||||
onClick={() =>
|
||||
navigate(`/login/withImg/${item.Name}/${item.Id}/`)
|
||||
navigate({
|
||||
to: "/login/$userId/$userName",
|
||||
params: { userId: item.Id, userName: item.Name },
|
||||
})
|
||||
}
|
||||
overrideIcon="User"
|
||||
imageType="Primary"
|
||||
|
||||
@@ -71,7 +71,7 @@ function ServerList() {
|
||||
await delUser();
|
||||
await servers.refetch();
|
||||
|
||||
if (servers.length > 0) {
|
||||
if (servers.length > 1) {
|
||||
setDefaultServer(servers[0].id);
|
||||
createApi(servers[0].address, undefined);
|
||||
} else {
|
||||
@@ -109,7 +109,7 @@ function ServerList() {
|
||||
style={{
|
||||
fontSize: "1.64em",
|
||||
}}
|
||||
onClick={() => navigate({ to: "/setup/server" })}
|
||||
onClick={() => navigate({ to: "/setup/server/add" })}
|
||||
>
|
||||
<div className="material-symbols-rounded">add</div>
|
||||
</IconButton>
|
||||
|
||||
Reference in new issue
Block a user