Auto login user if remember me enabled
This commit is contained in:
3 files changed
+68
-36
No files matched your search
+48
-16
@@ -52,6 +52,7 @@ import { Jellyfin } from "@jellyfin/sdk";
|
||||
import { version as appVer } from "../package.json";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { delServer, getServer } from "./utils/store/servers.js";
|
||||
import { getUser } from "./utils/store/user.js";
|
||||
|
||||
const jellyfin = new Jellyfin({
|
||||
clientInfo: {
|
||||
@@ -120,7 +121,6 @@ function App() {
|
||||
|
||||
const serverAvailable = async () => {
|
||||
const server = await getServer();
|
||||
console.log("Server Store => ", server);
|
||||
|
||||
if (server == null) {
|
||||
console.log("server not found");
|
||||
@@ -136,7 +136,6 @@ function App() {
|
||||
|
||||
const usersAvailable = async () => {
|
||||
const users = await getUserApi(window.api).getPublicUsers();
|
||||
console.log("Users => ", users);
|
||||
if (users.data.length >= 1) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -144,6 +143,16 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const userSaved = async () => {
|
||||
const user = await getUser();
|
||||
console.log("User store => ", user);
|
||||
if (user == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const pingServer = () => {
|
||||
let data;
|
||||
fetch(`${window.api.basePath}/System/Ping`, {
|
||||
@@ -170,17 +179,36 @@ function App() {
|
||||
});
|
||||
};
|
||||
|
||||
const userLogin = async () => {
|
||||
const user = await getUser();
|
||||
const auth = await api.authenticateUserByName(
|
||||
user.Name,
|
||||
user.Password,
|
||||
);
|
||||
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
||||
event.emit("set-api-accessToken", window.api.basePath);
|
||||
|
||||
navigate("/home");
|
||||
};
|
||||
|
||||
const LogicalRoutes = () => {
|
||||
serverAvailable().then(async (server) => {
|
||||
if (server == true) {
|
||||
pingServer();
|
||||
if (serverReachable == true) {
|
||||
usersAvailable().then((usersAvailablity) => {
|
||||
if (usersAvailablity == true) {
|
||||
console.log(usersAvailablity);
|
||||
navigate("/login/users");
|
||||
userSaved().then((user_available) => {
|
||||
if (user_available == true) {
|
||||
userLogin();
|
||||
} else {
|
||||
navigate("/login/manual");
|
||||
usersAvailable().then(
|
||||
(users_list_available) => {
|
||||
if (users_list_available == true) {
|
||||
navigate("/login/users");
|
||||
} else {
|
||||
navigate("/login/manual");
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -191,6 +219,16 @@ function App() {
|
||||
});
|
||||
};
|
||||
|
||||
const LoginLogicalRoutes = () => {
|
||||
usersAvailable().then((users_list_available) => {
|
||||
if (users_list_available == true) {
|
||||
navigate("/login/users");
|
||||
} else {
|
||||
navigate("/login/manual");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handleRelaunch = async () => {
|
||||
await relaunch();
|
||||
};
|
||||
@@ -279,17 +317,11 @@ function App() {
|
||||
path="/"
|
||||
element={<LogicalRoutes />}
|
||||
/>
|
||||
{/* <Route
|
||||
<Route
|
||||
exact
|
||||
path="/login"
|
||||
element={
|
||||
usersPresent ? (
|
||||
<Navigate to="/login/users"></Navigate>
|
||||
) : (
|
||||
<Navigate to="/login/manual"></Navigate>
|
||||
)
|
||||
}
|
||||
/> */}
|
||||
element={<LoginLogicalRoutes />}
|
||||
/>
|
||||
</Route>
|
||||
</Routes>
|
||||
</AnimatePresence>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/** @format */
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Cookies } from "react-cookie";
|
||||
|
||||
import { theme } from "../../theme";
|
||||
import "./home.module.scss";
|
||||
@@ -41,6 +40,7 @@ import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
const drawerWidth = 320;
|
||||
|
||||
@@ -61,7 +61,7 @@ const MiniDrawer = styled(MuiDrawer, {
|
||||
boxSizing: "border-box",
|
||||
backgroundColor: theme.palette.primary.background.dark,
|
||||
overflowX: "hidden",
|
||||
width: `calc(${theme.spacing(7)} + 1px)`,
|
||||
width: `calc(${theme.spacing(7)} + 10px)`,
|
||||
}));
|
||||
|
||||
const AppBar = styled(MuiAppBar, {
|
||||
@@ -86,12 +86,12 @@ export const Home = () => {
|
||||
Name: "",
|
||||
});
|
||||
|
||||
const navigate = useNavigate();
|
||||
const excludeTypes = ["boxsets", "playlists", "livetv", "channels"];
|
||||
|
||||
const [latestMedia, setLatestMedia] = useState([]);
|
||||
|
||||
const [drawerState, setDrawerState] = useState(false);
|
||||
const cookies = new Cookies();
|
||||
|
||||
const scrollTrigger = useScrollTrigger({ threshold: 5 });
|
||||
|
||||
@@ -105,6 +105,7 @@ export const Home = () => {
|
||||
|
||||
const handleLogout = async () => {
|
||||
await window.api.logout();
|
||||
navigate("/login");
|
||||
console.log("logged out user");
|
||||
};
|
||||
|
||||
@@ -184,6 +185,7 @@ export const Home = () => {
|
||||
sx: {
|
||||
backgroundColor: "inherit",
|
||||
border: "none",
|
||||
width: `calc(${theme.spacing(7)} + 10px)`,
|
||||
},
|
||||
}}
|
||||
>
|
||||
@@ -253,21 +255,10 @@ export const Home = () => {
|
||||
) : (
|
||||
<>
|
||||
<Skeleton
|
||||
height={50}
|
||||
variant="rectangular"
|
||||
animation="wave"
|
||||
></Skeleton>
|
||||
<br />
|
||||
<Skeleton
|
||||
height={50}
|
||||
variant="rectangular"
|
||||
animation="wave"
|
||||
></Skeleton>
|
||||
<br />
|
||||
<Skeleton
|
||||
height={50}
|
||||
variant="rectangular"
|
||||
animation="wave"
|
||||
height="100%"
|
||||
variant="rounded"
|
||||
width="calc(100% - 10px )"
|
||||
sx={{ margin: "5px" }}
|
||||
></Skeleton>
|
||||
</>
|
||||
)}
|
||||
|
||||
+11
-2
@@ -10,10 +10,19 @@ const user = new Store(".user.dat");
|
||||
* @param {string} userPassword - User's Password
|
||||
*/
|
||||
const saveUser = (userName, userPassword) => {
|
||||
let details = user.set("details", {
|
||||
let details = user.set("user", {
|
||||
Name: userName,
|
||||
Password: userPassword,
|
||||
});
|
||||
};
|
||||
|
||||
export { saveUser };
|
||||
/**
|
||||
* Get saved user fro .user.dat
|
||||
* @return {object}
|
||||
*/
|
||||
const getUser = async () => {
|
||||
let details = await user.get("user");
|
||||
return details;
|
||||
};
|
||||
|
||||
export { saveUser, getUser };
|
||||
Reference in new issue
Block a user