This commit is contained in:
sijinhui
2024-04-18 10:04:10 +08:00
parent 9ed72b8f47
commit 714ad21b74
3 changed files with 101 additions and 74 deletions

View File

@@ -51,7 +51,22 @@ async function handle(
},
});
const count = result.length;
return NextResponse.json({ count: count, results: result });
return NextResponse.json({
count: count,
results: result.map((item) => {
return {
id: item.id,
name: item.name,
username: item.username,
gh_username: item.gh_username,
image: item.image,
email: item.email,
emailVerified: item.emailVerified,
createdAt: item.createdAt,
updatedAt: item.updatedAt,
};
}),
});
} catch {}
return NextResponse.json({ error: "未知错误" }, { status: 500 });
}

View File

@@ -8,11 +8,16 @@ export default function UserLoginButton() {
const [loading, setLoading] = useState(false);
const nameInput = useRef<HTMLInputElement>(null);
const passwordInput = useRef<HTMLInputElement>(null);
const emailInput = useRef<HTMLInputElement>(null);
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState(false);
const handleComposition = (e: React.CompositionEvent<HTMLInputElement>) => {
const handleNameComposition = (
e: React.CompositionEvent<HTMLInputElement>,
) => {
if (e.type === "compositionend") {
setUsername(e.currentTarget.value);
}
@@ -23,6 +28,12 @@ export default function UserLoginButton() {
}
setUsername(e.target.value);
};
const onPasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if ((e.nativeEvent as InputEvent).isComposing) {
return;
}
setPassword(e.target.value);
};
const onSubmitHandler = async (e: React.FormEvent<HTMLFormElement>) => {
// handle yow submition
setLoading(true);
@@ -40,6 +51,7 @@ export default function UserLoginButton() {
} else {
result = await signIn("credentials", {
username: username,
password: password,
redirect: false,
});
}
@@ -93,7 +105,7 @@ export default function UserLoginButton() {
ref={nameInput}
// value={username}
onCompositionStart={(e) => e.preventDefault()}
onCompositionEnd={handleComposition}
onCompositionEnd={handleNameComposition}
onChange={onNameChange}
// required
placeholder="输入姓名、拼音或邮箱"
@@ -109,6 +121,29 @@ export default function UserLoginButton() {
}
`}
/>
<input
id="password"
name="password"
type="password"
ref={passwordInput}
value={password}
// onCompositionStart={(e) => e.preventDefault()}
// onCompositionEnd={handleComposition}
onChange={onPasswordChange}
// required
placeholder="密码验证,测试阶段"
className={`${
loading
? "cursor-not-allowed bg-stone-50 dark:bg-stone-800"
: "bg-white hover:bg-stone-50 active:bg-stone-100 dark:bg-black dark:hover:border-white dark:hover:bg-black"
} group my-2 flex h-10 w-full items-center justify-center space-x-2 rounded-md border border-stone-200 transition-colors duration-75 focus:outline-none dark:border-stone-700
${
error
? "focus:invalid:border-red-500 focus:invalid:ring-red-500"
: ""
}
`}
/>
<input
id="email"
name="email"