feat: redesigned login pages

This commit is contained in:
--remove-section committed 2026-10-20 18:36:02 +05:30
1 parent c232c1bf12
commit 61ebc66127
7 files changed
+660 -690

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api";
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
import { useQuery } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router";
import React, { type ReactNode, useEffect } from "react";
import { useApiInContext } from "@/utils/store/api";
import { useBackdropStore } from "@/utils/store/backdrop";
import "./loginShell.scss";
type LoginShellProps = {
title: ReactNode;
subtitle?: ReactNode;
/** Max width of the content column. */
width?: "narrow" | "wide";
children: ReactNode;
footer?: ReactNode;
};
/** Shared full-screen layout for the sign-in pages. */
const LoginShell = ({
title,
subtitle,
width = "narrow",
children,
footer,
}: LoginShellProps) => {
const api = useApiInContext((s) => s.api);
const serverInfo = useQuery({
queryKey: ["login", "serverInfo"],
queryFn: async () =>
api ? (await getSystemApi(api).getPublicSystemInfo()).data : null,
enabled: Boolean(api),
staleTime: 5 * 60_000,
});
const branding = useQuery({
queryKey: ["login", "branding"],
queryFn: async () =>
api ? (await getBrandingApi(api).getBrandingOptions()).data : null,
enabled: Boolean(api),
staleTime: 5 * 60_000,
});
const setBackdrop = useBackdropStore((s) => s.setBackdrop);
useEffect(() => {
setBackdrop("");
}, [setBackdrop]);
const serverName = serverInfo.data?.ServerName;
const serverHost = api?.basePath.replace(/^https?:\/\//, "");
return (
<div className="login-shell scrollY">
<div className={`login-shell-content login-shell-${width}`}>
{serverHost && (
<div className="login-shell-server">
<span className="material-symbols-rounded">dns</span>
<span className="login-shell-server-name" title={serverHost}>
{serverName ?? serverHost}
</span>
<Link to="/setup/server/list" className="login-shell-server-change">
Change
</Link>
</div>
)}
<header className="login-shell-header">
<h1 className="login-shell-title">{title}</h1>
{subtitle && <p className="login-shell-subtitle">{subtitle}</p>}
</header>
<main className="login-shell-body">{children}</main>
{footer && <footer className="login-shell-footer">{footer}</footer>}
{branding.data?.LoginDisclaimer && (
<aside className="login-shell-disclaimer">
<span className="material-symbols-rounded">info</span>
<p>{branding.data.LoginDisclaimer}</p>
</aside>
)}
</div>
</div>
);
};
export default LoginShell;
+278
View File
@@ -0,0 +1,278 @@
.login-shell {
// In normal flow (not fixed) so the app bar above stays clickable
position: relative;
min-height: 100vh;
width: 100%;
display: flex;
justify-content: center;
padding: 5rem 1.5rem 3rem;
box-sizing: border-box;
color: white;
// Soft accent glow instead of a boxed card
background:
radial-gradient(ellipse 60% 45% at 50% 0%, rgb(255 41 128 / 0.14), transparent 70%),
radial-gradient(ellipse 50% 40% at 50% 100%, rgb(110 0 184 / 0.18), transparent 70%);
&-content {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
margin: auto 0;
gap: 1.5rem;
}
&-narrow {
max-width: 380px;
}
&-wide {
max-width: 880px;
}
&-server {
display: inline-flex;
align-items: center;
gap: 0.5rem;
max-width: 100%;
padding: 0.35rem 0.5rem 0.35rem 0.75rem;
border-radius: 999px;
background: rgb(255 255 255 / 0.06);
border: 1px solid rgb(255 255 255 / 0.08);
font-size: 0.85rem;
.material-symbols-rounded {
font-size: 1.1rem;
opacity: 0.6;
}
&-name {
opacity: 0.85;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&-change {
flex-shrink: 0;
padding: 0.15rem 0.6rem;
border-radius: 999px;
color: white;
font-weight: 600;
text-decoration: none;
background: rgb(255 255 255 / 0.08);
transition: background 0.15s ease;
&:hover,
&:focus-visible {
background: rgb(255 255 255 / 0.16);
outline: none;
}
}
}
&-header {
text-align: center;
margin-top: 0.5rem;
}
&-title {
margin: 0;
font-size: clamp(1.75rem, 4vw, 2.5rem);
font-weight: 700;
letter-spacing: -0.02em;
line-height: 1.15;
}
&-subtitle {
margin: 0.5rem 0 0;
opacity: 0.65;
}
&-body {
width: 100%;
}
&-footer {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.5rem 1rem;
opacity: 0.85;
}
&-disclaimer {
display: flex;
gap: 0.6rem;
max-width: 480px;
padding: 0.9rem 1rem;
border-radius: 0.75rem;
background: rgb(255 255 255 / 0.04);
border: 1px solid rgb(255 255 255 / 0.08);
font-size: 0.85rem;
line-height: 1.5;
.material-symbols-rounded {
font-size: 1.2rem;
opacity: 0.6;
}
p {
margin: 0;
opacity: 0.75;
}
}
}
// Text-style secondary action used in login footers
.login-link {
all: unset;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.4rem 0.75rem;
border-radius: 999px;
font-size: 0.9rem;
color: rgb(255 255 255 / 0.75);
text-decoration: none;
transition: background 0.15s ease, color 0.15s ease;
.material-symbols-rounded {
font-size: 1.15rem;
}
&:hover,
&:focus-visible {
color: white;
background: rgb(255 255 255 / 0.08);
}
}
// Profile picker
.profile-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(128px, 148px));
justify-content: center;
gap: 1.5rem 1rem;
}
.profile {
all: unset;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
padding: 0.75rem 0.5rem;
border-radius: 1rem;
cursor: pointer;
color: white;
text-decoration: none;
text-align: center;
&-avatar {
position: relative;
width: 112px;
height: 112px;
border-radius: 50%;
// Ring that lights up on hover / focus
box-shadow: 0 0 0 3px transparent, 0 10px 24px rgb(0 0 0 / 0.4);
transition: box-shadow 0.2s ease, transform 0.2s ease;
img,
.profile-avatar-fallback {
width: 100%;
height: 100%;
border-radius: 50%;
object-fit: cover;
}
&-fallback {
display: flex;
align-items: center;
justify-content: center;
font-size: 2.75rem;
font-weight: 700;
background: linear-gradient(135deg, $clr-accent-default, $clr-secondary-default);
}
&-add {
display: flex;
align-items: center;
justify-content: center;
background: rgb(255 255 255 / 0.06);
border: 2px dashed rgb(255 255 255 / 0.25);
box-sizing: border-box;
.material-symbols-rounded {
font-size: 2.5rem;
opacity: 0.7;
}
}
}
&-lock {
position: absolute;
right: 2px;
bottom: 2px;
width: 28px;
height: 28px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
background: rgb(18 18 24);
border: 2px solid rgb(18 18 24);
box-sizing: border-box;
.material-symbols-rounded {
font-size: 1rem;
opacity: 0.8;
}
}
&-name {
max-width: 100%;
font-weight: 600;
opacity: 0.8;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
transition: opacity 0.2s ease;
}
&:hover,
&:focus-visible {
.profile-avatar {
transform: translateY(-3px);
box-shadow: 0 0 0 3px $clr-accent-default, 0 14px 30px rgb(0 0 0 / 0.5);
}
.profile-name {
opacity: 1;
}
}
}
// Password / manual sign-in form
.login-form {
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
&-avatar {
display: flex;
justify-content: center;
margin-bottom: 0.25rem;
.profile-avatar {
width: 96px;
height: 96px;
}
}
&-options {
display: flex;
align-items: center;
justify-content: space-between;
margin: -0.25rem 0;
}
&-submit.MuiButton-root {
height: 48px;
border-radius: 12px;
font-weight: 700;
text-transform: none;
font-size: 1rem;
}
}
@@ -0,0 +1,59 @@
import type { Api } from "@jellyfin/sdk";
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { queryOptions } from "@tanstack/react-query";
import React, { useState } from "react";
import { useApiInContext } from "@/utils/store/api";
/** Public (listed) users of the current server; shared by the login pages. */
export const getPublicUsersQueryOptions = (api: Api | null | undefined) =>
queryOptions({
queryKey: ["login", "public-users"],
queryFn: async () =>
api ? (await getUserApi(api).getPublicUsers()).data : [],
enabled: Boolean(api),
});
type ProfileAvatarProps = {
userId: string;
name: string;
imageTag?: string | null;
/** Shows a lock badge for password-protected profiles. */
locked?: boolean;
};
/** Round profile picture, falling back to the user's initial. */
export const ProfileAvatar = ({
userId,
name,
imageTag,
locked,
}: ProfileAvatarProps) => {
const api = useApiInContext((s) => s.api);
const [failed, setFailed] = useState(false);
const showImage = api && imageTag && !failed;
return (
<span className="profile-avatar">
{showImage ? (
<img
alt=""
src={`${api.basePath}/Users/${userId}/Images/Primary?quality=85&fillWidth=224&fillHeight=224&tag=${imageTag}`}
onError={() => setFailed(true)}
/>
) : (
<span className="profile-avatar-fallback" aria-hidden>
{name.trim().charAt(0).toUpperCase() || "?"}
</span>
)}
{locked && (
<span className="profile-lock" title="Password protected">
<span className="material-symbols-rounded">lock</span>
</span>
)}
</span>
);
};
export const isPasswordProtected = (user: UserDto | undefined) =>
user?.HasPassword !== false;
+95 -186
View File
@@ -1,108 +1,57 @@
import LoadingButton from "@mui/lab/LoadingButton"; import Button from "@mui/material/Button";
import { Paper, TextField, Typography } from "@mui/material";
import Checkbox from "@mui/material/Checkbox"; import Checkbox from "@mui/material/Checkbox";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import InputAdornment from "@mui/material/InputAdornment"; import InputAdornment from "@mui/material/InputAdornment";
import TextField from "@mui/material/TextField";
import { useSnackbar } from "notistack"; import { useMutation, useQuery } from "@tanstack/react-query";
import { AvatarImage } from "@/components/avatar/avatar.jsx";
import "./login.scss";
import { useMutation } from "@tanstack/react-query";
import { import {
createFileRoute, createFileRoute,
Link,
useNavigate, useNavigate,
useRouter, useRouter,
} from "@tanstack/react-router"; } from "@tanstack/react-router";
import React, { import React, { type FormEvent, useState } from "react";
type ChangeEvent, import LoginShell from "@/components/loginShell";
type FormEvent, import {
useEffect, getPublicUsersQueryOptions,
useState, isPasswordProtected,
} from "react"; ProfileAvatar,
import { useShallow } from "zustand/shallow"; } from "@/components/loginShell/profileAvatar";
import { saveUser } from "@/utils/storage/user"; import { saveUser } from "@/utils/storage/user";
import { useApiInContext } from "@/utils/store/api"; import { useApiInContext } from "@/utils/store/api";
import { useBackdropStore } from "@/utils/store/backdrop.js";
export const Route = createFileRoute("/_api/login/$userId/$userName")({ export const Route = createFileRoute("/_api/login/$userId/$userName")({
component: LoginUser, component: LoginUser,
}); });
type PasswordState = {
showpass: boolean;
password: string | undefined;
};
function LoginUser() { function LoginUser() {
const { userName, userId } = Route.useParams(); const { userName, userId } = Route.useParams();
const router = useRouter(); const router = useRouter();
const navigate = useNavigate({ from: "/login/$userId/$userName" });
const api = useApiInContext((s) => s.api); const api = useApiInContext((s) => s.api);
const createApi = useApiInContext((s) => s.createApi); const createApi = useApiInContext((s) => s.createApi);
const [password, setPassword] = useState<PasswordState>({ const [password, setPassword] = useState("");
showpass: false, const [showPassword, setShowPassword] = useState(false);
password: undefined,
});
const [rememberMe, setRememberMe] = useState(true); 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 handleLogin = useMutation({
mutationKey: ["login", "authenticate"],
const handlePassword = mutationFn: async () => {
(prop: "password" | "showPassord") => if (!api) throw new Error("API not initialized");
(event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { const authenticate = await api.authenticateUserByName(userName, password);
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,
);
if (!authenticate.data.AccessToken) { if (!authenticate.data.AccessToken) {
throw new Error("No access token received"); 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) { if (authenticate.data.SessionInfo?.UserId && rememberMe) {
await saveUser( await saveUser(
userName, userName,
@@ -110,158 +59,118 @@ function LoginUser() {
authenticate.data.SessionInfo.UserId, authenticate.data.SessionInfo.UserId,
); );
} }
},
onSuccess: () => {
router.invalidate().finally(() => { router.invalidate().finally(() => {
navigate({ to: "/home", replace: true }); navigate({ to: "/home", replace: true });
}); });
} catch (err) { },
onError: (err) => {
console.error(err); console.error(err);
enqueueSnackbar("Unable to authenticate! Please check your password", { setError(
variant: "error", needsPassword
? "Incorrect password. Please try again."
: "Couldn't sign in. Please try again.",
);
setPassword("");
},
}); });
}
return; const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
setError(null);
handleLogin.mutate();
}; };
const handleLogin = useMutation({
mutationKey: ["login", "authenticate"],
mutationFn: handleLoginFn,
});
return ( return (
<div <LoginShell
className="login flex flex-center flex-column centered" title={`Welcome back, ${userName}`}
style={{ marginTop: 0 }} 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 <form className="login-form" onSubmit={handleSubmit}>
sx={{ <div className="login-form-avatar">
p: 4, <ProfileAvatar
width: "100%", userId={userId}
maxWidth: "600px", name={userName}
backgroundColor: "rgba(20, 20, 30, 0.7)", imageTag={user?.PrimaryImageTag}
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>
</div> </div>
<form {needsPassword && (
onSubmit={(e) => handleLogin.mutate(e)}
style={{
width: "100%",
display: "flex",
flexDirection: "column",
gap: "1.5rem",
}}
>
<TextField <TextField
fullWidth fullWidth
type={password.showpass ? "text" : "password"} autoFocus
onChange={handlePassword("password")}
label="Password" label="Password"
variant="outlined" 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={{ slotProps={{
input: { input: {
startAdornment: (
<InputAdornment position="start">
<span
className="material-symbols-rounded"
style={{ opacity: 0.5 }}
>
key
</span>
</InputAdornment>
),
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton onClick={handleShowPassword} edge="end"> <IconButton
{password.showpass ? ( onClick={() => setShowPassword((show) => !show)}
edge="end"
aria-label={
showPassword ? "Hide password" : "Show password"
}
>
<span className="material-symbols-rounded"> <span className="material-symbols-rounded">
visibility {showPassword ? "visibility_off" : "visibility"}
</span> </span>
) : (
<span className="material-symbols-rounded">
visibility_off
</span>
)}
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
), ),
}, },
}} }}
/> />
)}
{!needsPassword && error && (
<p className="login-shell-subtitle" role="alert">
{error}
</p>
)}
<div <div className="login-form-options">
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
}}
>
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={rememberMe} checked={rememberMe}
onChange={handleCheckRememberMe} onChange={(_, checked) => setRememberMe(checked)}
/> />
} }
label="Remember me" label="Keep me signed in"
sx={{ m: 0 }}
/> />
</div> </div>
<LoadingButton <Button
className="login-form-submit"
variant="contained" variant="contained"
endIcon={<span className="material-symbols-rounded">login</span>}
type="submit" type="submit"
loading={handleLogin.isPending}
loadingPosition="end"
size="large" size="large"
fullWidth fullWidth
sx={{ borderRadius: 2, height: 48 }} loading={handleLogin.isPending || handleLogin.isSuccess}
> >
Login Sign in
</LoadingButton> </Button>
</form> </form>
</Paper> </LoginShell>
</div>
); );
} }
+60 -181
View File
@@ -1,197 +1,76 @@
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import Skeleton from "@mui/material/Skeleton";
import { Box, Chip, Typography } from "@mui/material";
import { useQuery } from "@tanstack/react-query"; 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 { 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 { 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")({ export const Route = createFileRoute("/_api/login/list")({
component: LoginPublicUsersList, 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() { function LoginPublicUsersList() {
const api = useApiInContext((s) => s.api); 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),
});
const setBackdrop = useBackdropStore((state) => state.setBackdrop);
useEffect(() => {
setBackdrop("");
}, []);
if (users.isSuccess) {
return ( return (
<div className="login-container scrollY flex flex-column flex-center"> <LoginShell
<Paper width="wide"
sx={{ title="Who's watching?"
p: 4, subtitle="Choose your profile to sign in"
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 <div className="profile-grid">
variant="h4" {users.isPending &&
align="center" [0, 1, 2].map((key) => (
sx={{ <div className="profile" key={key} aria-hidden>
fontWeight: "bold", <Skeleton variant="circular" width={112} height={112} />
}} <Skeleton variant="text" width={72} />
>
Select User
</Typography>
<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.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>
</div> </div>
))}
{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}`}
>
<ProfileAvatar
userId={user.Id ?? ""}
name={user.Name ?? ""}
imageTag={user.PrimaryImageTag}
locked={isPasswordProtected(user)}
/>
<span className="profile-name">{user.Name}</span>
</Link>
))}
{!users.isPending && (
<Link
className="profile"
to="/login/manual"
aria-label="Sign in with a username"
>
<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>
{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>
); );
}
if (users.isError) {
return <ErrorNotice />;
}
} }
-90
View File
@@ -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;
}
}
}
}
+80 -233
View File
@@ -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 Button from "@mui/material/Button";
import Checkbox from "@mui/material/Checkbox"; import Checkbox from "@mui/material/Checkbox";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import InputAdornment from "@mui/material/InputAdornment"; import InputAdornment from "@mui/material/InputAdornment";
import { useMutation, useQuery } from "@tanstack/react-query"; import TextField from "@mui/material/TextField";
import { useSnackbar } from "notistack"; import { useMutation } from "@tanstack/react-query";
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 { import {
createFileRoute, createFileRoute,
Link,
useNavigate, useNavigate,
useRouter, useRouter,
} from "@tanstack/react-router"; } from "@tanstack/react-router";
import { useShallow } from "zustand/shallow"; import React, { type FormEvent, useState } from "react";
import { useBackdropStore } from "@/utils/store/backdrop.js"; import LoginShell from "@/components/loginShell";
import { saveUser } from "@/utils/storage/user";
import { useApiInContext } from "@/utils/store/api";
export const Route = createFileRoute("/_api/login/manual")({ export const Route = createFileRoute("/_api/login/manual")({
component: UserLoginManual, component: UserLoginManual,
@@ -35,191 +24,112 @@ export const Route = createFileRoute("/_api/login/manual")({
}); });
function UserLoginManual() { function UserLoginManual() {
const [rememberMe, setRememberMe] = useState(true);
// console.log(Route.useRouteContext());
const api = useApiInContext((s) => s.api); const api = useApiInContext((s) => s.api);
const createApi = useApiInContext((s) => s.createApi); const createApi = useApiInContext((s) => s.createApi);
const router = useRouter(); const router = useRouter();
const navigate = useNavigate();
const searchParams = Route.useSearch(); 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 [username, setUsername] = useState("");
const [password, setPassword] = useState<{ const [password, setPassword] = useState("");
password: string | undefined; const [showPassword, setShowPassword] = useState(false);
showpass: boolean; const [rememberMe, setRememberMe] = useState(true);
}>({ const [error, setError] = useState<string | null>(null);
showpass: false,
password: "",
});
const handlePassword = const handleLogin = useMutation({
(prop: "password" | "showpass") => mutationKey: ["login", "authenticate"],
(event: ChangeEvent<HTMLInputElement>) => { mutationFn: async () => {
setPassword({ if (!api) throw new Error("Api is not available");
...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 authenticate = await api.authenticateUserByName( const authenticate = await api.authenticateUserByName(
username, username.trim(),
password.password, password,
); );
if (!authenticate.data?.AccessToken) { if (!authenticate.data?.AccessToken) {
throw new Error("Access token not available"); throw new Error("Access token not available");
} }
createApi(api.basePath, authenticate.data?.AccessToken); createApi(api.basePath, authenticate.data.AccessToken);
if (rememberMe) {
if (rememberMe)
await saveUser( await saveUser(
username, username.trim(),
authenticate.data.AccessToken, authenticate.data.AccessToken,
authenticate.data.User?.Id ?? "", authenticate.data.User?.Id ?? "",
); );
}
},
onSuccess: () => {
router.invalidate().finally(() => { router.invalidate().finally(() => {
navigate({ to: searchParams.redirect || "/home", replace: true }); navigate({ to: searchParams.redirect || "/home", replace: true });
}); });
} catch (err) { },
onError: (err) => {
console.error(err); console.error(err);
enqueueSnackbar( setError("Incorrect username or password.");
"Unable to authenticate. Please check your username and password", setPassword("");
{ variant: "error" }, },
);
}
return;
};
const handleLogin = useMutation({
mutationKey: ["login", "authenticate"],
mutationFn: handleLoginFn,
}); });
const handleCheckRememberMe = ( const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
_: ChangeEvent<HTMLInputElement>, event.preventDefault();
checked: boolean, if (!username.trim()) {
) => { setError("Enter your username.");
setRememberMe(checked); return;
}
setError(null);
handleLogin.mutate();
}; };
const setBackdrop = useBackdropStore(
useShallow((state) => state.setBackdrop),
);
useEffect(() => {
setBackdrop("");
}, []);
return ( return (
<div className="login scrollY flex flex-center flex-column"> <LoginShell
<Paper title="Sign in"
sx={{ subtitle="Use your username and password"
p: 4, footer={
width: "100%", <Link to="/login/list" className="login-link">
maxWidth: "600px", <span className="material-symbols-rounded">group</span>
backgroundColor: "rgba(20, 20, 30, 0.7)", Choose a profile instead
backdropFilter: "blur(24px) saturate(180%)", </Link>
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",
}}
>
Login
</Typography>
<form
className="flex flex-column"
style={{ gap: "1.5em", width: "100%" }}
onSubmit={(e) => handleLogin.mutate(e)}
> >
<form className="login-form" onSubmit={handleSubmit} noValidate>
<TextField <TextField
variant="outlined"
label="Username" // Label helps accessibility, theme handles style
fullWidth fullWidth
onChange={(e) => setUsername(e.currentTarget.value)} autoFocus
slotProps={{ label="Username"
input: { variant="outlined"
startAdornment: ( autoComplete="username"
<InputAdornment position="start"> value={username}
<span onChange={(e) => {
className="material-symbols-rounded" setUsername(e.target.value);
style={{ opacity: 0.5 }} setError(null);
>
person
</span>
</InputAdornment>
),
},
}} }}
error={Boolean(error) && !username.trim()}
/> />
<TextField <TextField
fullWidth fullWidth
type={password.showpass ? "text" : "password"}
onChange={handlePassword("password")}
label="Password" label="Password"
variant="outlined" 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={{ slotProps={{
input: { input: {
startAdornment: (
<InputAdornment position="start">
<span
className="material-symbols-rounded"
style={{ opacity: 0.5 }}
>
key
</span>
</InputAdornment>
),
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton <IconButton
onClick={handleShowPassword} onClick={() => setShowPassword((show) => !show)}
edge="end" edge="end"
sx={{ aria-label={
color: "rgba(255,255,255,0.7)", showPassword ? "Hide password" : "Show password"
"&:hover": { color: "#fff" }, }
}}
> >
{password.showpass ? (
<span className="material-symbols-rounded"> <span className="material-symbols-rounded">
visibility {showPassword ? "visibility_off" : "visibility"}
</span> </span>
) : (
<span className="material-symbols-rounded">
visibility_off
</span>
)}
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
), ),
@@ -227,92 +137,29 @@ function UserLoginManual() {
}} }}
/> />
<div className="login-form-options">
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={rememberMe} checked={rememberMe}
onChange={handleCheckRememberMe} onChange={(_, checked) => setRememberMe(checked)}
sx={{
color: "rgba(255,255,255,0.5)",
"&.Mui-checked": {
color: "primary.main",
},
}}
/> />
} }
label={ label="Keep me signed in"
<Typography variant="body2" sx={{ opacity: 0.7 }}>
Remember me
</Typography>
}
/> />
</div>
<div className="flex flex-column" style={{ gap: "1em" }}> <Button
<LoadingButton className="login-form-submit"
variant="contained" variant="contained"
type="submit" type="submit"
loading={handleLogin.isPending}
sx={{ width: "100%", height: 48, borderRadius: 2 }}
size="large" size="large"
fullWidth
loading={handleLogin.isPending || handleLogin.isSuccess}
> >
Login Sign in
</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> </Button>
</div>
</form> </form>
</Paper> </LoginShell>
{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)",
}}
>
<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>
); );
} }