diff --git a/frontend/src/components/layout/lst-sidebar.tsx b/frontend/src/components/layout/lst-sidebar.tsx
index 14ad5a4..ac2bbdf 100644
--- a/frontend/src/components/layout/lst-sidebar.tsx
+++ b/frontend/src/components/layout/lst-sidebar.tsx
@@ -17,11 +17,11 @@ export function AppSidebar() {
{moduleActive("production") && }
- {hasAccess(user, "logistics", "view") && moduleActive("logistics") && }
- {hasAccess(user, "forklift", "view") && moduleActive("forklift") && }
- {hasAccess(user, "eom", "view") && moduleActive("admin") && }
- {hasAccess(user, "quality", "view") && moduleActive("quality") && }
- {hasAccess(user, "admin", "view") && moduleActive("admin") && }
+ {moduleActive("logistics") && hasAccess(user, "logistics", "view") && }
+ {moduleActive("forklift") && hasAccess(user, "forklift", "view") && }
+ {moduleActive("admin") && hasAccess(user, "eom", "view") && }
+ {moduleActive("quality") && hasAccess(user, "quality", "view") && }
+ {moduleActive("admin") && hasAccess(user, "admin", "view") && }
diff --git a/frontend/src/lib/store/sessionStore.ts b/frontend/src/lib/store/sessionStore.ts
index 9d54c7c..a2400e7 100644
--- a/frontend/src/lib/store/sessionStore.ts
+++ b/frontend/src/lib/store/sessionStore.ts
@@ -28,7 +28,7 @@ export const useSessionStore = create((set) => {
localStorage.removeItem("auth_token");
}
- console.log("Setting session:", {user, token});
+ //console.log("Setting session:", {user, token});
set({user, token});
},
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index 383b219..9b5dc71 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -18,7 +18,7 @@ export default defineConfig({
},
server: {
proxy: {
- "/api": {target: "http://localhost:3000", changeOrigin: true},
+ "/api": {target: `http://localhost:4000`, changeOrigin: true},
},
},
});
diff --git a/package.json b/package.json
index 28695a9..2cf3604 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,6 @@
"drizzle-orm": "^0.39.3",
"drizzle-zod": "^0.7.0",
"hono": "^4.7.1",
- "http-proxy-middleware": "^3.0.3",
"jsonwebtoken": "^9.0.2",
"pg": "^8.13.3",
"postgres": "^3.4.5",
diff --git a/server/database/migrations/0005_tough_emma_frost.sql b/server/database/migrations/0005_tough_emma_frost.sql
new file mode 100644
index 0000000..0678470
--- /dev/null
+++ b/server/database/migrations/0005_tough_emma_frost.sql
@@ -0,0 +1 @@
+ALTER TABLE "users" ADD COLUMN "role" text DEFAULT 'user' NOT NULL;
\ No newline at end of file
diff --git a/server/database/migrations/meta/0005_snapshot.json b/server/database/migrations/meta/0005_snapshot.json
new file mode 100644
index 0000000..00e960d
--- /dev/null
+++ b/server/database/migrations/meta/0005_snapshot.json
@@ -0,0 +1,421 @@
+{
+ "id": "eb681265-0d44-4a8a-acaf-840acc169228",
+ "prevId": "313590a8-2068-45b5-96fc-cfa5d2b32b56",
+ "version": "7",
+ "dialect": "postgresql",
+ "tables": {
+ "public.modules": {
+ "name": "modules",
+ "schema": "",
+ "columns": {
+ "module_id": {
+ "name": "module_id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "active": {
+ "name": "active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "roles": {
+ "name": "roles",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'[\"view\", \"systemAdmin\"]'"
+ },
+ "add_User": {
+ "name": "add_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "add_Date": {
+ "name": "add_Date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ },
+ "upd_User": {
+ "name": "upd_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "upd_date": {
+ "name": "upd_date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "module_name": {
+ "name": "module_name",
+ "columns": [
+ {
+ "expression": "name",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.roles": {
+ "name": "roles",
+ "schema": "",
+ "columns": {
+ "role_id": {
+ "name": "role_id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "add_User": {
+ "name": "add_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "add_Date": {
+ "name": "add_Date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ },
+ "upd_User": {
+ "name": "upd_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "upd_date": {
+ "name": "upd_date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "role_name": {
+ "name": "role_name",
+ "columns": [
+ {
+ "expression": "name",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.userRoles": {
+ "name": "userRoles",
+ "schema": "",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role_id": {
+ "name": "role_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "module_id": {
+ "name": "module_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "add_User": {
+ "name": "add_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "add_Date": {
+ "name": "add_Date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ },
+ "upd_User": {
+ "name": "upd_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "upd_date": {
+ "name": "upd_date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "user_module_unique": {
+ "name": "user_module_unique",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "module_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "userRoles_user_id_users_user_id_fk": {
+ "name": "userRoles_user_id_users_user_id_fk",
+ "tableFrom": "userRoles",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "user_id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "userRoles_role_id_roles_role_id_fk": {
+ "name": "userRoles_role_id_roles_role_id_fk",
+ "tableFrom": "userRoles",
+ "tableTo": "roles",
+ "columnsFrom": [
+ "role_id"
+ ],
+ "columnsTo": [
+ "role_id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "userRoles_module_id_modules_module_id_fk": {
+ "name": "userRoles_module_id_modules_module_id_fk",
+ "tableFrom": "userRoles",
+ "tableTo": "modules",
+ "columnsFrom": [
+ "module_id"
+ ],
+ "columnsTo": [
+ "module_id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.users": {
+ "name": "users",
+ "schema": "",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "passwordToken": {
+ "name": "passwordToken",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "passwordTokenExpires": {
+ "name": "passwordTokenExpires",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "active": {
+ "name": "active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "pingcode": {
+ "name": "pingcode",
+ "type": "numeric",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'user'"
+ },
+ "lastLogin": {
+ "name": "lastLogin",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ },
+ "add_User": {
+ "name": "add_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "add_Date": {
+ "name": "add_Date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ },
+ "upd_User": {
+ "name": "upd_User",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'LST_System'"
+ },
+ "upd_date": {
+ "name": "upd_date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "username": {
+ "name": "username",
+ "columns": [
+ {
+ "expression": "username",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "sequences": {},
+ "roles": {},
+ "policies": {},
+ "views": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
\ No newline at end of file
diff --git a/server/database/migrations/meta/_journal.json b/server/database/migrations/meta/_journal.json
index ec56e92..ee8a4f9 100644
--- a/server/database/migrations/meta/_journal.json
+++ b/server/database/migrations/meta/_journal.json
@@ -36,6 +36,13 @@
"when": 1740364483791,
"tag": "0004_quick_mandrill",
"breakpoints": true
+ },
+ {
+ "idx": 5,
+ "version": "7",
+ "when": 1740445275919,
+ "tag": "0005_tough_emma_frost",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/server/database/schema/users.ts b/server/database/schema/users.ts
index 7d02c3c..94dc665 100644
--- a/server/database/schema/users.ts
+++ b/server/database/schema/users.ts
@@ -13,6 +13,7 @@ export const users = pgTable(
passwordTokenExpires: timestamp("passwordTokenExpires"),
acitve: boolean("active").default(true).notNull(),
pinCode: numeric("pingcode"),
+ role: text("role").default("user").notNull(), // temp column while we migrate the front end
lastLogin: timestamp("lastLogin").defaultNow(),
add_User: text("add_User").default("LST_System").notNull(),
add_Date: timestamp("add_Date").defaultNow(),
diff --git a/server/src/app.ts b/server/src/app.ts
index 353bfb2..6063a3d 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -8,17 +8,18 @@ import {OpenAPIHono} from "@hono/zod-openapi";
import auth from "./services/auth/authService";
import scalar from "./services/general/route/scalar";
import apiHits from "./services/general/route/apitHits";
-import getModules from "./services/general/route/getModules";
-// services
-import {ocmeService} from "./services/ocme/ocmeServer";
+import system from "./services/system/systemServer";
const app = new OpenAPIHono();
app.use("*", logger());
+
+const allowedOrigins = ["http://localhost:3000", "http://localhost:4000", "http://localhost:5173"];
+
app.use(
"*",
cors({
- origin: `http://localhost:5173`,
+ origin: allowedOrigins,
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
allowMethods: ["POST", "GET", "OPTIONS"],
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
@@ -36,11 +37,11 @@ app.doc("/api", {
});
// as we dont want to change ocme again well use a proxy to this
-app.all("/ocme/*", async (c) => {
- return ocmeService(c);
-});
+// app.all("/ocme/*", async (c) => {
+// return ocmeService(c);
+// });
-const routes = [scalar, auth, apiHits, getModules] as const;
+const routes = [scalar, auth, apiHits, system] as const;
routes.forEach((route) => {
app.route("/api/", route);
diff --git a/server/src/services/auth/controllers/login.ts b/server/src/services/auth/controllers/login.ts
index 3bd400d..54b26d7 100644
--- a/server/src/services/auth/controllers/login.ts
+++ b/server/src/services/auth/controllers/login.ts
@@ -15,12 +15,13 @@ export async function login(
): Promise<{token: string; user: {user_id: string; username: string}}> {
const user = await db.select().from(users).where(eq(users.username, username));
+ console.log(user);
if (user.length === 0) {
throw new Error("Invalid or Missing user");
}
// check the password
const checkedPass = await checkPassword(password, user[0]?.password);
- console.log(checkedPass);
+ //console.log(checkedPass);
if (!checkedPass) {
throw new Error("Invalid Password");
}
@@ -36,8 +37,9 @@ export async function login(
username: user[0].username,
email: user[0].email,
roles: roles || null,
+ role: user[0].role || null, // this should be removed onces full migration to v2 is completed
};
const token = sign({user: userData}, secret, {expiresIn: expiresIn * 60});
- return {token, user: {user_id: user[0].user_id, username: user[0].username}};
+ return {token, user: userData};
}
diff --git a/server/src/services/auth/routes/login.ts b/server/src/services/auth/routes/login.ts
index 130378a..27f4e15 100644
--- a/server/src/services/auth/routes/login.ts
+++ b/server/src/services/auth/routes/login.ts
@@ -75,7 +75,6 @@ app.openapi(route, async (c) => {
);
}
- const {token, user} = await login(username.toLowerCase(), password);
try {
const {token, user} = await login(username.toLowerCase(), password);
diff --git a/server/src/services/auth/utils/checkPassword.ts b/server/src/services/auth/utils/checkPassword.ts
index 75ccdb2..2866852 100644
--- a/server/src/services/auth/utils/checkPassword.ts
+++ b/server/src/services/auth/utils/checkPassword.ts
@@ -1,10 +1,16 @@
import bcrypt from "bcrypt";
export const checkPassword = async (currentPassword: string, dbPassword: string) => {
+ let decyptPass = "";
+ try {
+ decyptPass = atob(dbPassword);
+ } catch (error) {
+ console.log(error);
+ }
// encypt password
const pass: string | undefined = process.env.SECRET;
- const checked = bcrypt.compareSync(pass + currentPassword, dbPassword);
+ const checked = bcrypt.compareSync(pass + currentPassword, decyptPass);
return checked;
};
diff --git a/server/src/services/auth/utils/createPassword.ts b/server/src/services/auth/utils/createPassword.ts
index f071ebd..1a0aa9f 100644
--- a/server/src/services/auth/utils/createPassword.ts
+++ b/server/src/services/auth/utils/createPassword.ts
@@ -10,7 +10,7 @@ export const createPassword = async (password: string) => {
} else {
pass = bcrypt.hashSync(pass + password, parseInt(salt));
- // pass = btoa(pass);
+ pass = btoa(pass);
}
return pass;
diff --git a/server/src/services/general/route/scalar.ts b/server/src/services/general/route/scalar.ts
index 8c403ee..da5ed34 100644
--- a/server/src/services/general/route/scalar.ts
+++ b/server/src/services/general/route/scalar.ts
@@ -52,11 +52,11 @@ app.get(
baseServerURL: "https://scalar.com",
servers: [
{
- url: "http://usday1vms006:3000",
+ url: `http://usday1vms006:${process.env.SERVER_PORT}`,
description: "Production",
},
{
- url: "http://localhost:3000",
+ url: `http://localhost:${process.env.SERVER_PORT}`,
description: "dev server",
},
],
diff --git a/server/src/services/general/route/getModules.ts b/server/src/services/system/route/modules.ts
similarity index 94%
rename from server/src/services/general/route/getModules.ts
rename to server/src/services/system/route/modules.ts
index 3828e68..3166ff6 100644
--- a/server/src/services/general/route/getModules.ts
+++ b/server/src/services/system/route/modules.ts
@@ -38,11 +38,6 @@ app.openapi(
},
}),
async (c) => {
- //const data = await c.req.json();
-
- //apiHit(data);
-
- // get the modules that are active
let module: any = [];
try {
module = await db.select().from(modules).where(eq(modules.active, true));
diff --git a/server/src/services/system/systemServer.ts b/server/src/services/system/systemServer.ts
new file mode 100644
index 0000000..d3518fa
--- /dev/null
+++ b/server/src/services/system/systemServer.ts
@@ -0,0 +1,7 @@
+import {OpenAPIHono} from "@hono/zod-openapi";
+
+import modules from "./route/modules";
+
+const app = new OpenAPIHono().route("system/module", modules);
+
+export default app;