feaeet: add passkeys support
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { Alert, Button, Card, CloseButton, Input, Label, TextField } from "@heroui/react";
|
||||
import { Thunderbolt } from "@gravity-ui/icons";
|
||||
import { Fingerprint, Thunderbolt } from "@gravity-ui/icons";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
|
||||
export default function LoginPage() {
|
||||
@@ -14,6 +14,7 @@ export default function LoginPage() {
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [passkeyLoading, setPasskeyLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -38,6 +39,24 @@ export default function LoginPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handlePasskey = async () => {
|
||||
setError("");
|
||||
setPasskeyLoading(true);
|
||||
try {
|
||||
const res = await authClient.signIn.passkey();
|
||||
if (res?.error) {
|
||||
setError(res.error.message ?? "Passkey 登录失败");
|
||||
} else {
|
||||
router.push("/dashboard");
|
||||
router.refresh();
|
||||
}
|
||||
} catch {
|
||||
setError("Passkey 登录失败,请重试");
|
||||
} finally {
|
||||
setPasskeyLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-dvh flex-col items-center justify-center bg-background px-4">
|
||||
{/* Brand */}
|
||||
@@ -97,6 +116,27 @@ export default function LoginPage() {
|
||||
<Button className="mt-2 w-full" isDisabled={loading} type="submit">
|
||||
{loading ? "登录中…" : "登录"}
|
||||
</Button>
|
||||
<div className="relative flex items-center gap-3">
|
||||
<div className="h-px flex-1 bg-border" />
|
||||
<span className="text-xs text-muted">或</span>
|
||||
<div className="h-px flex-1 bg-border" />
|
||||
</div>
|
||||
<Button
|
||||
className="w-full"
|
||||
variant="secondary"
|
||||
isDisabled={passkeyLoading}
|
||||
type="button"
|
||||
onPress={handlePasskey}
|
||||
>
|
||||
{passkeyLoading ? (
|
||||
"验证中…"
|
||||
) : (
|
||||
<>
|
||||
<Fingerprint className="size-4" />
|
||||
使用 Passkey 登录
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</form>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user