intial setting and auth intergrated
This commit is contained in:
@@ -4,12 +4,12 @@ import {
|
||||
admin,
|
||||
apiKey,
|
||||
createAuthMiddleware,
|
||||
customSession,
|
||||
//customSession,
|
||||
jwt,
|
||||
lastLoginMethod,
|
||||
username,
|
||||
} from "better-auth/plugins";
|
||||
import { eq } from "drizzle-orm";
|
||||
//import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import * as rawSchema from "../db/schema/auth.schema.js";
|
||||
import { allowedOrigins } from "./cors.utils.js";
|
||||
@@ -31,20 +31,15 @@ export const auth = betterAuth({
|
||||
provider: "pg",
|
||||
schema,
|
||||
}),
|
||||
user: {
|
||||
additionalFields: {
|
||||
role: {
|
||||
type: "string",
|
||||
required: false,
|
||||
input: false,
|
||||
},
|
||||
lastLogin: {
|
||||
type: "date",
|
||||
required: true,
|
||||
input: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
// user: {
|
||||
// additionalFields: {
|
||||
// role: {
|
||||
// type: "string",
|
||||
// //required: false,
|
||||
// input: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
plugins: [
|
||||
jwt({ jwt: { expirationTime: "1h" } }),
|
||||
apiKey(),
|
||||
@@ -53,26 +48,27 @@ export const auth = betterAuth({
|
||||
username({
|
||||
minUsernameLength: 5,
|
||||
usernameValidator: (username) => {
|
||||
if (username === "admin") {
|
||||
if (username === "admin" || username === "root") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}),
|
||||
customSession(async ({ user, session }) => {
|
||||
const roles = await db
|
||||
.select({ roles: rawSchema.user.role })
|
||||
.from(rawSchema.user)
|
||||
.where(eq(rawSchema.user.id, session.id));
|
||||
return {
|
||||
roles,
|
||||
user: {
|
||||
...user,
|
||||
//newField: "newField",
|
||||
},
|
||||
session,
|
||||
};
|
||||
}),
|
||||
|
||||
// customSession(async ({ user, session }) => {
|
||||
// const roles = await db
|
||||
// .select({ roles: rawSchema.user.role })
|
||||
// .from(rawSchema.user)
|
||||
// .where(eq(rawSchema.user.id, session.id));
|
||||
// return {
|
||||
// roles,
|
||||
// user: {
|
||||
// ...user,
|
||||
// //newField: "newField",
|
||||
// },
|
||||
// session,
|
||||
// };
|
||||
// }),
|
||||
],
|
||||
trustedOrigins: allowedOrigins,
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Response } from "express";
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
|
||||
interface Data {
|
||||
interface Data<T = unknown[]> {
|
||||
success: boolean;
|
||||
module: "system" | "ocp" | "routes" | "datamart" | "utils" | "opendock";
|
||||
subModule:
|
||||
@@ -14,10 +14,11 @@ interface Data {
|
||||
| "auth"
|
||||
| "datamart"
|
||||
| "jobs"
|
||||
| "apt";
|
||||
| "apt"
|
||||
| "settings";
|
||||
level: "info" | "error" | "debug" | "fatal";
|
||||
message: string;
|
||||
data?: unknown[];
|
||||
data?: T;
|
||||
notify?: boolean;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user