mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-06-02 13:13:43 -04:00
34 lines
878 B
TypeScript
34 lines
878 B
TypeScript
import { verifyPassword } from "better-auth/crypto";
|
|
import { db } from "~/server/db/db";
|
|
|
|
type PasswordVerificationBody = {
|
|
userId: string;
|
|
password: string;
|
|
};
|
|
|
|
export const verifyUserPassword = async ({ password, userId }: PasswordVerificationBody) => {
|
|
const userAccount = await db.query.account.findFirst({
|
|
where: { AND: [{ userId }, { providerId: "credential" }] },
|
|
});
|
|
|
|
if (!userAccount || !userAccount.password) {
|
|
return false;
|
|
}
|
|
|
|
const isPasswordValid = await verifyPassword({ password: password, hash: userAccount.password });
|
|
if (!isPasswordValid) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
export const userHasCredentialPassword = async (userId: string) => {
|
|
const userAccount = await db.query.account.findFirst({
|
|
where: { AND: [{ userId }, { providerId: "credential" }] },
|
|
columns: { password: true },
|
|
});
|
|
|
|
return Boolean(userAccount?.password);
|
|
};
|