refactor: add 2fa

This commit is contained in:
Mauricio Siu
2025-02-16 20:56:50 -06:00
parent e1632cbdb3
commit 0e8e92c715
7 changed files with 119 additions and 65 deletions

View File

@@ -1,9 +1,9 @@
import {
boolean,
integer,
pgTable,
text,
integer,
timestamp,
boolean,
} from "drizzle-orm/pg-core";
export const users_temp = pgTable("users_temp", {

View File

@@ -16,7 +16,16 @@ export const auth = betterAuth({
provider: "pg",
schema: schema,
}),
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
},
emailAndPassword: {
enabled: true,

View File

@@ -106,26 +106,25 @@ export const isAdminPresent = async () => {
};
export const getUserByToken = async (token: string) => {
// const user = await db.query.users.findFirst({
// where: eq(users.token, token),
// with: {
// auth: {
// columns: {
// password: false,
// },
// },
// },
// });
// if (!user) {
// throw new TRPCError({
// code: "NOT_FOUND",
// message: "Invitation not found",
// });
// }
// return {
// ...user,
// isExpired: user.isRegistered,
// };
const user = await db.query.users_temp.findFirst({
where: eq(users_temp.token, token),
columns: {
id: true,
email: true,
token: true,
isRegistered: true,
},
});
if (!user) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Invitation not found",
});
}
return {
...user,
isExpired: user.isRegistered,
};
};
export const removeUserById = async (userId: string) => {

View File

@@ -29,16 +29,15 @@ class LogRotationManager {
}
private async getStateFromDB(): Promise<boolean> {
const setting = await db.query.admins.findFirst({});
return setting?.enableLogRotation ?? false;
// const setting = await db.query.admins.findFirst({});
// return setting?.enableLogRotation ?? false;
}
private async setStateInDB(active: boolean): Promise<void> {
const admin = await db.query.admins.findFirst({});
if (!admin) {
return;
}
// const admin = await db.query.admins.findFirst({});
// if (!admin) {
// return;
// }
// await updateAdmin(admin?.authId, {
// enableLogRotation: active,
// });