import React, { useState } from "react"; import * as jellyfin from "../../jellyfin"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { View } from "../index"; import LoadingIndicatorButton from "../loading-indicator-button"; import styles from "../../styles.module.css"; interface Props { setView: React.Dispatch>; } export default function PasswordView({ setView }: Props) { const [isLoading, setIsLoading] = useState(false); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const login = async () => { if (!jellyfin.api) return; setIsLoading(true); const userApi = getUserApi(jellyfin.api); const auth = await userApi.authenticateUserByName({ authenticateUserByName: { Username: username, Pw: password } }); if (!auth.data.AccessToken) { Spicetify.showNotification("Failed to login!", true); setIsLoading(false); return; } jellyfin.api.accessToken = auth.data.AccessToken; Spicetify.LocalStorage.set("jellyfin-token", auth.data.AccessToken); const user = await getUserApi(jellyfin.api).getCurrentUser(); if (user.data.Id) jellyfin.setUser(user.data.Id); setView("settings"); setIsLoading(false); }; return ( <>
setUsername(e.target.value)} />
setPassword(e.target.value)} />
Log in ); }