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