Merge pull request #67 from sijinhui/dev

update login
This commit is contained in:
sijinhui 2024-04-18 17:31:41 +08:00 committed by GitHub
commit 2fb6833238
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View File

@ -47,22 +47,26 @@ export default function UserLoginButton() {
window.location.href = window.location.href =
result?.url && result.url.includes("verify") ? result.url : "/"; result?.url && result.url.includes("verify") ? result.url : "/";
} else { } else {
const errorParts = result.error.split(","); if (loginProvider === "credentials") {
if (errorParts.length > 1) {
loginForm.setFields([ loginForm.setFields([
{ {
name: errorParts[0], name: "username",
errors: [errorParts[1]], errors: [result.error],
}, },
]);
} else {
loginForm.setFields([
{ {
name: "password", name: "password",
errors: [result.error], errors: [result.error],
}, },
]); ]);
} }
if (loginProvider === "email") {
loginForm.setFields([
{
name: "email",
errors: [result.error],
},
]);
}
} }
console.log("response,", result); console.log("response,", result);
}); });

View File

@ -99,12 +99,12 @@ export const authOptions: NextAuthOptions = {
existingUser = await insertUser(user); existingUser = await insertUser(user);
} }
// 有密码就校验密码,没有就直接返回用户 // 有密码就校验密码,没有就直接返回用户
password && validatePassword(password, existingUser.password); (password || existingUser.password) && validatePassword(password, existingUser.password);
return existingUser; return existingUser;
} else { } else {
// If you return null then an error will be displayed advising the user to check their details. // If you return null then an error will be displayed advising the user to check their details.
// return null // return null
throw new Error("username,用户名校验失败") throw new Error("用户名校验失败")
// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
} }
} }
@ -196,11 +196,11 @@ export async function VerifiedAdminUser() {
export function validatePassword(password: string, hashPassword: string | null | undefined ): boolean | void { export function validatePassword(password: string, hashPassword: string | null | undefined ): boolean | void {
if (!hashPassword) { if (!hashPassword) {
throw new Error("password,未设置密码"); throw new Error("未设置密码");
} }
if (!comparePassword(password, hashPassword)) { if (!comparePassword(password, hashPassword)) {
throw new Error("password,用户名或密码不正确") throw new Error("用户名或密码不正确")
} else { } else {
return true; return true;
} }
@ -235,7 +235,7 @@ export async function insertUser(user: {[key: string]: string}) {
// return existingUser; // return existingUser;
// } // }
} catch (e) { } catch (e) {
throw new Error("username,用户创建失败"); throw new Error("用户创建失败");
// return false; // return false;
} }
} }