mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-12 17:00:23 +01:00
The protection picker used to show before the login attempt, so a wrong password still walked the user through choosing a PIN/password for an account that never logged in - and a Quick Connect login could not save the account at all. Login flows now only flag the intent (pendingAccountSaveAtom); the picker is a global PendingAccountSaveModal mounted at the root, shown once the session is authorized - the login screen unmounts on success, so it cannot host the modal itself. Works identically for the password and Quick Connect flows; the credential is saved from the live session token (saveCurrentAccount). Cancelling saves nothing, and a logout before answering drops the intent.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { useAtom, useAtomValue } from "jotai";
|
|
import type React from "react";
|
|
import { useEffect } from "react";
|
|
import { Platform } from "react-native";
|
|
import { SaveAccountModal } from "@/components/SaveAccountModal";
|
|
import {
|
|
pendingAccountSaveAtom,
|
|
useJellyfin,
|
|
userAtom,
|
|
} from "@/providers/JellyfinProvider";
|
|
|
|
/**
|
|
* Post-login save-account prompt. Login flows (password or Quick Connect)
|
|
* only flag the intent via pendingAccountSaveAtom; the protection picker
|
|
* shows here, AFTER the session is authorized — the login screen itself
|
|
* unmounts as soon as the user is set, so it can't host the modal.
|
|
*/
|
|
export const PendingAccountSaveModal: React.FC = () => {
|
|
const [pending, setPending] = useAtom(pendingAccountSaveAtom);
|
|
const user = useAtomValue(userAtom);
|
|
const { saveCurrentAccount } = useJellyfin();
|
|
|
|
// A logout before answering drops the intent — it must not resurface on
|
|
// the next (possibly different) login.
|
|
useEffect(() => {
|
|
if (!user && pending) setPending(null);
|
|
}, [user, pending, setPending]);
|
|
|
|
if (Platform.isTV) return null;
|
|
|
|
return (
|
|
<SaveAccountModal
|
|
visible={!!pending && !!user}
|
|
username={user?.Name ?? ""}
|
|
onClose={() => setPending(null)}
|
|
onSave={(securityType, pinCode) => {
|
|
const serverName = pending?.serverName;
|
|
setPending(null);
|
|
saveCurrentAccount({ securityType, pinCode, serverName }).catch(
|
|
() => {},
|
|
);
|
|
}}
|
|
/>
|
|
);
|
|
};
|