feat: redesigned login pages
This commit is contained in:
7 files changed
+703
-733
No files matched your search
@@ -1,108 +1,57 @@
|
||||
import LoadingButton from "@mui/lab/LoadingButton";
|
||||
import { Paper, TextField, Typography } from "@mui/material";
|
||||
import Button from "@mui/material/Button";
|
||||
import Checkbox from "@mui/material/Checkbox";
|
||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
import { AvatarImage } from "@/components/avatar/avatar.jsx";
|
||||
import "./login.scss";
|
||||
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import {
|
||||
createFileRoute,
|
||||
Link,
|
||||
useNavigate,
|
||||
useRouter,
|
||||
} from "@tanstack/react-router";
|
||||
import React, {
|
||||
type ChangeEvent,
|
||||
type FormEvent,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import React, { type FormEvent, useState } from "react";
|
||||
import LoginShell from "@/components/loginShell";
|
||||
import {
|
||||
getPublicUsersQueryOptions,
|
||||
isPasswordProtected,
|
||||
ProfileAvatar,
|
||||
} from "@/components/loginShell/profileAvatar";
|
||||
import { saveUser } from "@/utils/storage/user";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop.js";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/$userId/$userName")({
|
||||
component: LoginUser,
|
||||
});
|
||||
|
||||
type PasswordState = {
|
||||
showpass: boolean;
|
||||
password: string | undefined;
|
||||
};
|
||||
|
||||
function LoginUser() {
|
||||
const { userName, userId } = Route.useParams();
|
||||
|
||||
const router = useRouter();
|
||||
const navigate = useNavigate({ from: "/login/$userId/$userName" });
|
||||
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const createApi = useApiInContext((s) => s.createApi);
|
||||
|
||||
const [password, setPassword] = useState<PasswordState>({
|
||||
showpass: false,
|
||||
password: undefined,
|
||||
});
|
||||
const [password, setPassword] = useState("");
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const navigate = useNavigate({ from: "/login/$userId/$userName" });
|
||||
// Profile details (image, whether a password is needed) from the public user list
|
||||
const users = useQuery(getPublicUsersQueryOptions(api));
|
||||
const user = users.data?.find((u) => u.Id === userId);
|
||||
const needsPassword = isPasswordProtected(user);
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const handlePassword =
|
||||
(prop: "password" | "showPassord") =>
|
||||
(event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
setPassword({
|
||||
...password,
|
||||
[prop]: event.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
const handleShowPassword = () => {
|
||||
setPassword({
|
||||
...password,
|
||||
showpass: !password.showpass,
|
||||
});
|
||||
};
|
||||
|
||||
const setBackdrop = useBackdropStore(
|
||||
useShallow((state) => state.setBackdrop),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api) {
|
||||
return;
|
||||
}
|
||||
setBackdrop("");
|
||||
}, []);
|
||||
|
||||
const handleCheckRememberMe = (
|
||||
_: ChangeEvent<HTMLInputElement>,
|
||||
checked: boolean,
|
||||
) => {
|
||||
setRememberMe(checked);
|
||||
};
|
||||
|
||||
const handleLoginFn = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
if (!api) {
|
||||
throw new Error("API not initialized");
|
||||
}
|
||||
const authenticate = await api.authenticateUserByName(
|
||||
userName,
|
||||
password.password,
|
||||
);
|
||||
const handleLogin = useMutation({
|
||||
mutationKey: ["login", "authenticate"],
|
||||
mutationFn: async () => {
|
||||
if (!api) throw new Error("API not initialized");
|
||||
const authenticate = await api.authenticateUserByName(userName, password);
|
||||
if (!authenticate.data.AccessToken) {
|
||||
throw new Error("No access token received");
|
||||
}
|
||||
createApi(api.basePath, authenticate.data?.AccessToken);
|
||||
|
||||
createApi(api.basePath, authenticate.data.AccessToken);
|
||||
if (authenticate.data.SessionInfo?.UserId && rememberMe) {
|
||||
await saveUser(
|
||||
userName,
|
||||
@@ -110,158 +59,118 @@ function LoginUser() {
|
||||
authenticate.data.SessionInfo.UserId,
|
||||
);
|
||||
}
|
||||
|
||||
},
|
||||
onSuccess: () => {
|
||||
router.invalidate().finally(() => {
|
||||
navigate({ to: "/home", replace: true });
|
||||
});
|
||||
} catch (err) {
|
||||
},
|
||||
onError: (err) => {
|
||||
console.error(err);
|
||||
enqueueSnackbar("Unable to authenticate! Please check your password", {
|
||||
variant: "error",
|
||||
});
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
const handleLogin = useMutation({
|
||||
mutationKey: ["login", "authenticate"],
|
||||
mutationFn: handleLoginFn,
|
||||
setError(
|
||||
needsPassword
|
||||
? "Incorrect password. Please try again."
|
||||
: "Couldn't sign in. Please try again.",
|
||||
);
|
||||
setPassword("");
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setError(null);
|
||||
handleLogin.mutate();
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="login flex flex-center flex-column centered"
|
||||
style={{ marginTop: 0 }}
|
||||
<LoginShell
|
||||
title={`Welcome back, ${userName}`}
|
||||
subtitle={
|
||||
needsPassword
|
||||
? "Enter your password to continue"
|
||||
: "This profile doesn't need a password"
|
||||
}
|
||||
footer={
|
||||
<Link to="/login/list" className="login-link">
|
||||
<span className="material-symbols-rounded">switch_account</span>
|
||||
Not you? Switch user
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
<Paper
|
||||
sx={{
|
||||
p: 4,
|
||||
width: "100%",
|
||||
maxWidth: "600px",
|
||||
backgroundColor: "rgba(20, 20, 30, 0.7)",
|
||||
backdropFilter: "blur(24px) saturate(180%)",
|
||||
backgroundImage:
|
||||
"linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0))",
|
||||
border: "1px solid rgba(255, 255, 255, 0.08)",
|
||||
boxShadow: "0 20px 50px rgba(0,0,0,0.5)",
|
||||
borderRadius: 4,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
marginBottom: "2em",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
gap: "1em",
|
||||
}}
|
||||
>
|
||||
<AvatarImage userId={userId} />
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Typography variant="body1" sx={{ opacity: 0.7 }}>
|
||||
Login as
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
className="gradient-text"
|
||||
sx={{
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{userName}
|
||||
</Typography>
|
||||
</div>
|
||||
<form className="login-form" onSubmit={handleSubmit}>
|
||||
<div className="login-form-avatar">
|
||||
<ProfileAvatar
|
||||
userId={userId}
|
||||
name={userName}
|
||||
imageTag={user?.PrimaryImageTag}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<form
|
||||
onSubmit={(e) => handleLogin.mutate(e)}
|
||||
style={{
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "1.5rem",
|
||||
}}
|
||||
>
|
||||
{needsPassword && (
|
||||
<TextField
|
||||
fullWidth
|
||||
type={password.showpass ? "text" : "password"}
|
||||
onChange={handlePassword("password")}
|
||||
autoFocus
|
||||
label="Password"
|
||||
variant="outlined"
|
||||
autoFocus
|
||||
type={showPassword ? "text" : "password"}
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(e) => {
|
||||
setPassword(e.target.value);
|
||||
setError(null);
|
||||
}}
|
||||
error={Boolean(error)}
|
||||
helperText={error}
|
||||
slotProps={{
|
||||
input: {
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ opacity: 0.5 }}
|
||||
>
|
||||
key
|
||||
</span>
|
||||
</InputAdornment>
|
||||
),
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<IconButton onClick={handleShowPassword} edge="end">
|
||||
{password.showpass ? (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility
|
||||
</span>
|
||||
) : (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility_off
|
||||
</span>
|
||||
)}
|
||||
<IconButton
|
||||
onClick={() => setShowPassword((show) => !show)}
|
||||
edge="end"
|
||||
aria-label={
|
||||
showPassword ? "Hide password" : "Show password"
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
{showPassword ? "visibility_off" : "visibility"}
|
||||
</span>
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{!needsPassword && error && (
|
||||
<p className="login-shell-subtitle" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={handleCheckRememberMe}
|
||||
/>
|
||||
}
|
||||
label="Remember me"
|
||||
sx={{ m: 0 }}
|
||||
/>
|
||||
</div>
|
||||
<div className="login-form-options">
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={(_, checked) => setRememberMe(checked)}
|
||||
/>
|
||||
}
|
||||
label="Keep me signed in"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<LoadingButton
|
||||
variant="contained"
|
||||
endIcon={<span className="material-symbols-rounded">login</span>}
|
||||
type="submit"
|
||||
loading={handleLogin.isPending}
|
||||
loadingPosition="end"
|
||||
size="large"
|
||||
fullWidth
|
||||
sx={{ borderRadius: 2, height: 48 }}
|
||||
>
|
||||
Login
|
||||
</LoadingButton>
|
||||
</form>
|
||||
</Paper>
|
||||
</div>
|
||||
<Button
|
||||
className="login-form-submit"
|
||||
variant="contained"
|
||||
type="submit"
|
||||
size="large"
|
||||
fullWidth
|
||||
loading={handleLogin.isPending || handleLogin.isSuccess}
|
||||
>
|
||||
Sign in
|
||||
</Button>
|
||||
</form>
|
||||
</LoginShell>
|
||||
);
|
||||
}
|
||||
+59
-180
@@ -1,197 +1,76 @@
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { Box, Chip, Typography } from "@mui/material";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice.jsx";
|
||||
import "./login.scss";
|
||||
|
||||
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { Paper } from "@mui/material";
|
||||
import { createFileRoute, Link } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
import LoginShell from "@/components/loginShell";
|
||||
import {
|
||||
getPublicUsersQueryOptions,
|
||||
isPasswordProtected,
|
||||
ProfileAvatar,
|
||||
} from "@/components/loginShell/profileAvatar";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop.js";
|
||||
import avatar from "../../../assets/icons/avatar.png";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/list")({
|
||||
component: LoginPublicUsersList,
|
||||
});
|
||||
|
||||
const UserCard = ({ user }: { user: UserDto }) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
return (
|
||||
<Link
|
||||
to="/login/$userId/$userName"
|
||||
params={{ userId: user.Id ?? "", userName: user.Name ?? "" }}
|
||||
className="user-list-item user-card"
|
||||
style={{ textDecoration: "none", display: "block" }}
|
||||
>
|
||||
<Paper
|
||||
elevation={0}
|
||||
sx={{
|
||||
p: 2,
|
||||
bgcolor: "rgba(255,255,255,0.03)",
|
||||
"&:hover": {
|
||||
bgcolor: "rgba(255,255,255,0.1)",
|
||||
transform: "translateY(-4px)",
|
||||
boxShadow: "0 8px 20px rgba(0,0,0,0.3)",
|
||||
},
|
||||
transition: "all 0.3s ease",
|
||||
borderRadius: 4,
|
||||
border: "1px solid rgba(255,255,255,0.05)",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
width: "160px",
|
||||
height: "100%",
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="user-card-image-container"
|
||||
style={{
|
||||
width: "100px",
|
||||
height: "100px",
|
||||
borderRadius: "50%",
|
||||
overflow: "hidden",
|
||||
boxShadow: "0 8px 16px rgba(0,0,0,0.3)",
|
||||
}}
|
||||
>
|
||||
{user.PrimaryImageTag ? (
|
||||
<img
|
||||
className="user-card-image"
|
||||
alt={"user"}
|
||||
src={`${api?.basePath}/Users/${user.Id}/Images/Primary?quality=80&tag=${user.PrimaryImageTag}`}
|
||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
||||
/>
|
||||
) : (
|
||||
<img
|
||||
className="user-card-image"
|
||||
alt="user"
|
||||
src={avatar}
|
||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<Typography
|
||||
align="center"
|
||||
variant="subtitle1"
|
||||
noWrap
|
||||
sx={{
|
||||
mt: 2,
|
||||
fontWeight: "bold",
|
||||
width: "100%",
|
||||
color: "text.primary",
|
||||
}}
|
||||
>
|
||||
{user.Name}
|
||||
</Typography>
|
||||
</Paper>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
function LoginPublicUsersList() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const users = useQuery(getPublicUsersQueryOptions(api));
|
||||
|
||||
const users = useQuery({
|
||||
queryKey: ["login", "public-users"],
|
||||
queryFn: async () => {
|
||||
if (!api) return [];
|
||||
const result = await getUserApi(api).getPublicUsers();
|
||||
return result.data;
|
||||
},
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
return (
|
||||
<LoginShell
|
||||
width="wide"
|
||||
title="Who's watching?"
|
||||
subtitle="Choose your profile to sign in"
|
||||
>
|
||||
<div className="profile-grid">
|
||||
{users.isPending &&
|
||||
[0, 1, 2].map((key) => (
|
||||
<div className="profile" key={key} aria-hidden>
|
||||
<Skeleton variant="circular" width={112} height={112} />
|
||||
<Skeleton variant="text" width={72} />
|
||||
</div>
|
||||
))}
|
||||
|
||||
const setBackdrop = useBackdropStore((state) => state.setBackdrop);
|
||||
useEffect(() => {
|
||||
setBackdrop("");
|
||||
}, []);
|
||||
|
||||
if (users.isSuccess) {
|
||||
return (
|
||||
<div className="login-container scrollY flex flex-column flex-center">
|
||||
<Paper
|
||||
sx={{
|
||||
p: 4,
|
||||
maxWidth: "800px",
|
||||
width: "90%",
|
||||
backgroundColor: "rgba(20, 20, 30, 0.7)",
|
||||
backdropFilter: "blur(24px) saturate(180%)",
|
||||
backgroundImage:
|
||||
"linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0))",
|
||||
border: "1px solid rgba(255, 255, 255, 0.08)",
|
||||
boxShadow: "0 20px 50px rgba(0,0,0,0.5)",
|
||||
borderRadius: 4,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
gap: 3,
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="h4"
|
||||
align="center"
|
||||
sx={{
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
{users.data?.map((user) => (
|
||||
<Link
|
||||
key={user.Id}
|
||||
className="profile"
|
||||
to="/login/$userId/$userName"
|
||||
params={{ userId: user.Id ?? "", userName: user.Name ?? "" }}
|
||||
aria-label={`Sign in as ${user.Name}`}
|
||||
>
|
||||
Select User
|
||||
</Typography>
|
||||
<ProfileAvatar
|
||||
userId={user.Id ?? ""}
|
||||
name={user.Name ?? ""}
|
||||
imageTag={user.PrimaryImageTag}
|
||||
locked={isPasswordProtected(user)}
|
||||
/>
|
||||
<span className="profile-name">{user.Name}</span>
|
||||
</Link>
|
||||
))}
|
||||
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexWrap: "wrap",
|
||||
gap: 3,
|
||||
justifyContent: "center",
|
||||
width: "100%",
|
||||
maxHeight: "60vh",
|
||||
overflowY: "auto",
|
||||
py: 2,
|
||||
"&::-webkit-scrollbar": { display: "none" },
|
||||
scrollbarWidth: "none",
|
||||
}}
|
||||
{!users.isPending && (
|
||||
<Link
|
||||
className="profile"
|
||||
to="/login/manual"
|
||||
aria-label="Sign in with a username"
|
||||
>
|
||||
{users.data.map((item) => {
|
||||
return <UserCard user={item} key={item.Id} />;
|
||||
})}
|
||||
</Box>
|
||||
|
||||
<Chip
|
||||
label={
|
||||
<Typography variant="body2" align="center">
|
||||
Don't see your user? Try using{" "}
|
||||
<Link
|
||||
to="/login/manual"
|
||||
style={{ color: "inherit", fontWeight: "bold" }}
|
||||
>
|
||||
Manual Login
|
||||
</Link>{" "}
|
||||
or{" "}
|
||||
<Link
|
||||
to="/setup/server/list"
|
||||
style={{ color: "inherit", fontWeight: "bold" }}
|
||||
>
|
||||
Changing Server
|
||||
</Link>
|
||||
</Typography>
|
||||
}
|
||||
sx={{
|
||||
bgcolor: "rgba(255,255,255,0.05)",
|
||||
p: 1,
|
||||
height: "auto",
|
||||
"& .MuiChip-label": {
|
||||
padding: "8px 12px",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Paper>
|
||||
<span className="profile-avatar profile-avatar-add">
|
||||
<span className="material-symbols-rounded">person_add</span>
|
||||
</span>
|
||||
<span className="profile-name">Other user</span>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (users.isError) {
|
||||
return <ErrorNotice />;
|
||||
}
|
||||
|
||||
{users.isError && (
|
||||
<p className="login-shell-subtitle" style={{ textAlign: "center" }}>
|
||||
Couldn't load profiles from this server. Use "Other user" to sign in
|
||||
with your username.
|
||||
</p>
|
||||
)}
|
||||
</LoginShell>
|
||||
);
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
|
||||
.user {
|
||||
&-list {
|
||||
&-container {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
gap: 1em;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 30em;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scroll-snap-type: y mandatory;
|
||||
margin: 2em 0;
|
||||
}
|
||||
}
|
||||
&-card {
|
||||
width: fit-content;
|
||||
scroll-snap-align: start;
|
||||
text-decoration: none !important;
|
||||
color: white !important;
|
||||
&-image{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
&-container{
|
||||
aspect-ratio: 1;
|
||||
width: 8em;
|
||||
overflow: hidden;
|
||||
border-radius: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
&Icon {
|
||||
font-size: 5em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: $clr-accent-dark;
|
||||
}
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
width: 100%;
|
||||
>* {
|
||||
flex: 1 1 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.login {
|
||||
// width: 50em;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
&-container{
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
margin: auto;
|
||||
padding-top: 4em;
|
||||
padding-bottom: 4em;
|
||||
}
|
||||
|
||||
&-form {
|
||||
width: 24em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: stretch;
|
||||
gap:1em;
|
||||
&-container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap:2em;
|
||||
background: rgb(255 255 255 / 0.05);
|
||||
padding: 2em;
|
||||
border-radius: 20px;
|
||||
// border: 1px solid rgb(255 255 255 / 0.1);
|
||||
&.padded-top {
|
||||
margin-top: 25vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+107
-260
@@ -1,31 +1,20 @@
|
||||
import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api";
|
||||
import LoadingButton from "@mui/lab/LoadingButton";
|
||||
import { Paper, TextField, Typography } from "@mui/material";
|
||||
import Button from "@mui/material/Button";
|
||||
import Checkbox from "@mui/material/Checkbox";
|
||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useSnackbar } from "notistack";
|
||||
import React, {
|
||||
type ChangeEvent,
|
||||
type FormEvent,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import { saveUser } from "@/utils/storage/user.js";
|
||||
import { useApiInContext } from "@/utils/store/api.js";
|
||||
import "./login.scss";
|
||||
|
||||
import { blue } from "@mui/material/colors";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import {
|
||||
createFileRoute,
|
||||
Link,
|
||||
useNavigate,
|
||||
useRouter,
|
||||
} from "@tanstack/react-router";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop.js";
|
||||
import React, { type FormEvent, useState } from "react";
|
||||
import LoginShell from "@/components/loginShell";
|
||||
import { saveUser } from "@/utils/storage/user";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/manual")({
|
||||
component: UserLoginManual,
|
||||
@@ -35,284 +24,142 @@ export const Route = createFileRoute("/_api/login/manual")({
|
||||
});
|
||||
|
||||
function UserLoginManual() {
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
// console.log(Route.useRouteContext());
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const createApi = useApiInContext((s) => s.createApi);
|
||||
const router = useRouter();
|
||||
const navigate = useNavigate();
|
||||
const searchParams = Route.useSearch();
|
||||
|
||||
const server = useQuery({
|
||||
queryKey: ["login", "manual", "serverInfo"],
|
||||
queryFn: async () =>
|
||||
api ? (await getBrandingApi(api).getBrandingOptions()).data : null,
|
||||
});
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState<{
|
||||
password: string | undefined;
|
||||
showpass: boolean;
|
||||
}>({
|
||||
showpass: false,
|
||||
password: "",
|
||||
});
|
||||
const [password, setPassword] = useState("");
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const handlePassword =
|
||||
(prop: "password" | "showpass") =>
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
setPassword({
|
||||
...password,
|
||||
[prop]: event.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
const handleShowPassword = () => {
|
||||
setPassword({
|
||||
...password,
|
||||
showpass: !password.showpass,
|
||||
});
|
||||
};
|
||||
|
||||
const handleLoginFn = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
if (!api) {
|
||||
throw new Error("Api is not available");
|
||||
}
|
||||
const handleLogin = useMutation({
|
||||
mutationKey: ["login", "authenticate"],
|
||||
mutationFn: async () => {
|
||||
if (!api) throw new Error("Api is not available");
|
||||
const authenticate = await api.authenticateUserByName(
|
||||
username,
|
||||
password.password,
|
||||
username.trim(),
|
||||
password,
|
||||
);
|
||||
if (!authenticate.data?.AccessToken) {
|
||||
throw new Error("Access token not available");
|
||||
}
|
||||
createApi(api.basePath, authenticate.data?.AccessToken);
|
||||
|
||||
if (rememberMe)
|
||||
createApi(api.basePath, authenticate.data.AccessToken);
|
||||
if (rememberMe) {
|
||||
await saveUser(
|
||||
username,
|
||||
username.trim(),
|
||||
authenticate.data.AccessToken,
|
||||
authenticate.data.User?.Id ?? "",
|
||||
);
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
router.invalidate().finally(() => {
|
||||
navigate({ to: searchParams.redirect || "/home", replace: true });
|
||||
});
|
||||
} catch (err) {
|
||||
},
|
||||
onError: (err) => {
|
||||
console.error(err);
|
||||
enqueueSnackbar(
|
||||
"Unable to authenticate. Please check your username and password",
|
||||
{ variant: "error" },
|
||||
);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
const handleLogin = useMutation({
|
||||
mutationKey: ["login", "authenticate"],
|
||||
mutationFn: handleLoginFn,
|
||||
setError("Incorrect username or password.");
|
||||
setPassword("");
|
||||
},
|
||||
});
|
||||
|
||||
const handleCheckRememberMe = (
|
||||
_: ChangeEvent<HTMLInputElement>,
|
||||
checked: boolean,
|
||||
) => {
|
||||
setRememberMe(checked);
|
||||
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (!username.trim()) {
|
||||
setError("Enter your username.");
|
||||
return;
|
||||
}
|
||||
setError(null);
|
||||
handleLogin.mutate();
|
||||
};
|
||||
|
||||
const setBackdrop = useBackdropStore(
|
||||
useShallow((state) => state.setBackdrop),
|
||||
);
|
||||
useEffect(() => {
|
||||
setBackdrop("");
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="login scrollY flex flex-center flex-column">
|
||||
<Paper
|
||||
sx={{
|
||||
p: 4,
|
||||
width: "100%",
|
||||
maxWidth: "600px",
|
||||
backgroundColor: "rgba(20, 20, 30, 0.7)",
|
||||
backdropFilter: "blur(24px) saturate(180%)",
|
||||
backgroundImage:
|
||||
"linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0))",
|
||||
border: "1px solid rgba(255, 255, 255, 0.08)",
|
||||
boxShadow: "0 20px 50px rgba(0,0,0,0.5)",
|
||||
borderRadius: 4,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 3,
|
||||
mb: 3,
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="h4"
|
||||
align="center"
|
||||
sx={{
|
||||
fontWeight: "bold",
|
||||
<LoginShell
|
||||
title="Sign in"
|
||||
subtitle="Use your username and password"
|
||||
footer={
|
||||
<Link to="/login/list" className="login-link">
|
||||
<span className="material-symbols-rounded">group</span>
|
||||
Choose a profile instead
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
<form className="login-form" onSubmit={handleSubmit} noValidate>
|
||||
<TextField
|
||||
fullWidth
|
||||
autoFocus
|
||||
label="Username"
|
||||
variant="outlined"
|
||||
autoComplete="username"
|
||||
value={username}
|
||||
onChange={(e) => {
|
||||
setUsername(e.target.value);
|
||||
setError(null);
|
||||
}}
|
||||
>
|
||||
Login
|
||||
</Typography>
|
||||
<form
|
||||
className="flex flex-column"
|
||||
style={{ gap: "1.5em", width: "100%" }}
|
||||
onSubmit={(e) => handleLogin.mutate(e)}
|
||||
>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
label="Username" // Label helps accessibility, theme handles style
|
||||
fullWidth
|
||||
onChange={(e) => setUsername(e.currentTarget.value)}
|
||||
slotProps={{
|
||||
input: {
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ opacity: 0.5 }}
|
||||
>
|
||||
person
|
||||
error={Boolean(error) && !username.trim()}
|
||||
/>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Password"
|
||||
variant="outlined"
|
||||
type={showPassword ? "text" : "password"}
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(e) => {
|
||||
setPassword(e.target.value);
|
||||
setError(null);
|
||||
}}
|
||||
error={Boolean(error) && Boolean(username.trim())}
|
||||
helperText={error ?? "Leave blank if your account has no password"}
|
||||
slotProps={{
|
||||
input: {
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
onClick={() => setShowPassword((show) => !show)}
|
||||
edge="end"
|
||||
aria-label={
|
||||
showPassword ? "Hide password" : "Show password"
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
{showPassword ? "visibility_off" : "visibility"}
|
||||
</span>
|
||||
</InputAdornment>
|
||||
),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<TextField
|
||||
fullWidth
|
||||
type={password.showpass ? "text" : "password"}
|
||||
onChange={handlePassword("password")}
|
||||
label="Password"
|
||||
variant="outlined"
|
||||
slotProps={{
|
||||
input: {
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ opacity: 0.5 }}
|
||||
>
|
||||
key
|
||||
</span>
|
||||
</InputAdornment>
|
||||
),
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
onClick={handleShowPassword}
|
||||
edge="end"
|
||||
sx={{
|
||||
color: "rgba(255,255,255,0.7)",
|
||||
"&:hover": { color: "#fff" },
|
||||
}}
|
||||
>
|
||||
{password.showpass ? (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility
|
||||
</span>
|
||||
) : (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility_off
|
||||
</span>
|
||||
)}
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="login-form-options">
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={handleCheckRememberMe}
|
||||
sx={{
|
||||
color: "rgba(255,255,255,0.5)",
|
||||
"&.Mui-checked": {
|
||||
color: "primary.main",
|
||||
},
|
||||
}}
|
||||
onChange={(_, checked) => setRememberMe(checked)}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Typography variant="body2" sx={{ opacity: 0.7 }}>
|
||||
Remember me
|
||||
</Typography>
|
||||
}
|
||||
label="Keep me signed in"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-column" style={{ gap: "1em" }}>
|
||||
<LoadingButton
|
||||
variant="contained"
|
||||
type="submit"
|
||||
loading={handleLogin.isPending}
|
||||
sx={{ width: "100%", height: 48, borderRadius: 2 }}
|
||||
size="large"
|
||||
>
|
||||
Login
|
||||
</LoadingButton>
|
||||
<Button
|
||||
color="inherit"
|
||||
variant="text"
|
||||
sx={{
|
||||
width: "100%",
|
||||
color: "rgba(255,255,255,0.5)",
|
||||
"&:hover": {
|
||||
color: "white",
|
||||
bgcolor: "rgba(255,255,255,0.05)",
|
||||
},
|
||||
}}
|
||||
onClick={() => navigate({ to: "/setup/server/list" })}
|
||||
>
|
||||
Change Server
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Paper>
|
||||
{server.isSuccess && server.data?.LoginDisclaimer && (
|
||||
<Paper
|
||||
elevation={0}
|
||||
sx={{
|
||||
padding: "1.5em",
|
||||
borderRadius: "16px",
|
||||
width: "100%",
|
||||
maxWidth: "450px",
|
||||
backgroundColor: "rgba(33, 150, 243, 0.1)",
|
||||
border: "1px solid rgba(33, 150, 243, 0.2)",
|
||||
}}
|
||||
<Button
|
||||
className="login-form-submit"
|
||||
variant="contained"
|
||||
type="submit"
|
||||
size="large"
|
||||
fullWidth
|
||||
loading={handleLogin.isPending || handleLogin.isSuccess}
|
||||
>
|
||||
<div
|
||||
className="flex flex-row flex-align-center"
|
||||
style={{ gap: "0.5em", marginBottom: "0.5em" }}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
color: blue[400],
|
||||
}}
|
||||
>
|
||||
info
|
||||
</span>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
sx={{
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
>
|
||||
Notice
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography variant="body2" style={{ opacity: 0.8, lineHeight: 1.6 }}>
|
||||
{server.data.LoginDisclaimer}
|
||||
</Typography>
|
||||
</Paper>
|
||||
)}
|
||||
</div>
|
||||
Sign in
|
||||
</Button>
|
||||
</form>
|
||||
</LoginShell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user