refactor: implement new login logic and verify context.api status
This commit is contained in:
1 parent
b1737b82e8
commit
b8552ac35d
25 files changed
+589
-513
No files matched your search
+24
-1
@@ -4,7 +4,8 @@ import {
|
||||
getServer,
|
||||
} from "@/utils/storage/servers";
|
||||
import { getUser } from "@/utils/storage/user";
|
||||
import { axiosClient } from "@/utils/store/api";
|
||||
import { axiosClient, useApiInContext } from "@/utils/store/api";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
@@ -12,6 +13,7 @@ import { Suspense } from "react";
|
||||
|
||||
export const Route = createFileRoute("/_api")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
console.log(context.api);
|
||||
if (!context.api) {
|
||||
const currentServerId = await getDefaultServer();
|
||||
if (currentServerId) {
|
||||
@@ -23,6 +25,27 @@ export const Route = createFileRoute("/_api")({
|
||||
context.createApi(currentServer?.address, undefined); // Creates Api
|
||||
}
|
||||
}
|
||||
} else if (context.api) {
|
||||
try {
|
||||
await getSystemApi(context.api).getPingSystem(); // Verify server status
|
||||
} catch (error) {
|
||||
throw redirect({
|
||||
to: "/setup/server/error",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
try {
|
||||
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
|
||||
} catch (error) {
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user