Compare commits
4 Commits
379f7b836d
...
89a2b3ea9e
| Author | SHA1 | Date | |
|---|---|---|---|
| 89a2b3ea9e | |||
| d3acdfb481 | |||
| 6c3199fecc | |||
| 0ddcfaeaa9 |
@@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:4000/api/auth/login
|
||||
url: http://localhost:4400/api/auth/login
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@ meta {
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:3000/api/auth/register
|
||||
url: http://localhost:4400/api/auth/register
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username": "adm_matthes01",
|
||||
"email":"blake@alpla.com",
|
||||
"password": "nova0511!"
|
||||
"username": "matthes01",
|
||||
"email":"blake.matthes@alpla.com",
|
||||
"password": "password"
|
||||
}
|
||||
}
|
||||
|
||||
15
apiDocs/lstV2/Auth/getUserroles.bru
Normal file
15
apiDocs/lstV2/Auth/getUserroles.bru
Normal file
@@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: getUserroles
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:4400/api/auth/getuseraccess
|
||||
body: json
|
||||
auth: bearer
|
||||
}
|
||||
|
||||
auth:bearer {
|
||||
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJfaWQiOiIyYzYzODQ3Zi1mMWVjLTRkNTAtOGFkMi05ODBkMWYzZTgwZWIiLCJ1c2VybmFtZSI6Im1hdHRoZXMwMSIsImVtYWlsIjoiYmxha2UubWF0dGhlc0BhbHBsYS5jb20iLCJyb2xlcyI6W10sInJvbGUiOiJ1c2VyIn0sImlhdCI6MTc0MDY3NTMyMiwiZXhwIjoxNzQwNjc4OTIyfQ.D4rLIBAZfo0larMGUmXF6Z2KVnZvRLvth2116JyK2z8
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
|
||||
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
|
||||
import {z} from "zod";
|
||||
import {text, pgTable, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
|
||||
import {createSelectSchema} from "drizzle-zod";
|
||||
//import {z} from "zod";
|
||||
|
||||
export const modules = pgTable(
|
||||
"modules",
|
||||
@@ -26,3 +26,5 @@ export const modules = pgTable(
|
||||
// });
|
||||
// Schema for selecting a Expenses - can be used to validate API responses
|
||||
export const selectModuleSchema = createSelectSchema(modules);
|
||||
|
||||
export type Modules = typeof modules;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
|
||||
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
|
||||
import {z} from "zod";
|
||||
import {users} from "./users";
|
||||
import {roles} from "./roles";
|
||||
import {modules} from "./modules";
|
||||
import {users} from "./users.js";
|
||||
import {roles} from "./roles.js";
|
||||
import {modules} from "./modules.js";
|
||||
|
||||
/*
|
||||
we will add the user
|
||||
|
||||
12
drizzle.config.js
Normal file
12
drizzle.config.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from "drizzle-kit";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
const database = process.env.DATABASE_URL || "";
|
||||
export default defineConfig({
|
||||
dialect: "postgresql",
|
||||
schema: "database/schema",
|
||||
out: "database/migrations",
|
||||
dbCredentials: {
|
||||
url: database,
|
||||
},
|
||||
});
|
||||
144
frontend/package-lock.json
generated
144
frontend/package-lock.json
generated
@@ -23,7 +23,9 @@
|
||||
"@tanstack/react-router": "^1.111.11",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"hono": "^4.7.2",
|
||||
"js-cookie": "^3.0.5",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lucide-react": "^0.476.0",
|
||||
"next-themes": "^0.4.4",
|
||||
"react": "^19.0.0",
|
||||
@@ -43,6 +45,7 @@
|
||||
"@tanstack/router-plugin": "^1.106.0",
|
||||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@types/react-grid-layout": "^1.3.5",
|
||||
"@vitejs/plugin-react-swc": "^3.8.0",
|
||||
"eslint": "^9.21.0",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
@@ -2909,6 +2912,16 @@
|
||||
"@types/react": "^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/react-grid-layout": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/react-grid-layout/-/react-grid-layout-1.3.5.tgz",
|
||||
"integrity": "sha512-WH/po1gcEcoR6y857yAnPGug+ZhkF4PaTUxgAbwfeSH/QOgVSakKHBXoPGad/sEznmkiaK3pqHk+etdWisoeBQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/react": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "8.25.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.25.0.tgz",
|
||||
@@ -3317,6 +3330,12 @@
|
||||
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
||||
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/callsites": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
|
||||
@@ -3533,6 +3552,15 @@
|
||||
"node": ">=0.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ecdsa-sig-formatter": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.5.107",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.107.tgz",
|
||||
@@ -4029,6 +4057,15 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/hono": {
|
||||
"version": "4.7.2",
|
||||
"resolved": "https://registry.npmjs.org/hono/-/hono-4.7.2.tgz",
|
||||
"integrity": "sha512-8V5XxoOF6SI12jkHkzX/6aLBMU5GEF5g387EjVSQipS0DlxWgWGSMeEayY3CRBjtTUQYwLHx9JYouWqKzy2Vng==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
@@ -4202,6 +4239,49 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/jsonwebtoken": {
|
||||
"version": "9.0.2",
|
||||
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz",
|
||||
"integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jws": "^3.2.2",
|
||||
"lodash.includes": "^4.3.0",
|
||||
"lodash.isboolean": "^3.0.3",
|
||||
"lodash.isinteger": "^4.0.4",
|
||||
"lodash.isnumber": "^3.0.3",
|
||||
"lodash.isplainobject": "^4.0.6",
|
||||
"lodash.isstring": "^4.0.1",
|
||||
"lodash.once": "^4.0.0",
|
||||
"ms": "^2.1.1",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12",
|
||||
"npm": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/jwa": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
|
||||
"integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"buffer-equal-constant-time": "1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/jws": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
|
||||
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jwa": "^1.4.1",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/keyv": {
|
||||
"version": "4.5.4",
|
||||
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
|
||||
@@ -4470,6 +4550,42 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash.includes": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
||||
"integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isboolean": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
|
||||
"integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isinteger": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
||||
"integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isnumber": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
|
||||
"integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isplainobject": {
|
||||
"version": "4.0.6",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
||||
"integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isstring": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
|
||||
"integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.merge": {
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
|
||||
@@ -4477,6 +4593,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.once": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/loose-envify": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||
@@ -4549,7 +4671,6 @@
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
@@ -5089,6 +5210,26 @@
|
||||
"queue-microtask": "^1.2.2"
|
||||
}
|
||||
},
|
||||
"node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/scheduler": {
|
||||
"version": "0.25.0",
|
||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz",
|
||||
@@ -5099,7 +5240,6 @@
|
||||
"version": "7.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
||||
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"build": "rimraf dist && tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"shad": "npx shadcn@canary add "
|
||||
@@ -26,7 +26,9 @@
|
||||
"@tanstack/react-router": "^1.111.11",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"hono": "^4.7.2",
|
||||
"js-cookie": "^3.0.5",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lucide-react": "^0.476.0",
|
||||
"next-themes": "^0.4.4",
|
||||
"react": "^19.0.0",
|
||||
@@ -46,6 +48,7 @@
|
||||
"@tanstack/router-plugin": "^1.106.0",
|
||||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@types/react-grid-layout": "^1.3.5",
|
||||
"@vitejs/plugin-react-swc": "^3.8.0",
|
||||
"eslint": "^9.21.0",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
|
||||
@@ -9,19 +9,23 @@ import {AdminSideBar} from "./side-components/admin";
|
||||
import {useSessionStore} from "../../lib/store/sessionStore";
|
||||
import {hasAccess} from "../../utils/userAccess";
|
||||
import {moduleActive} from "../../utils/moduleActive";
|
||||
import {useModuleStore} from "../../lib/store/useModuleStore";
|
||||
|
||||
export function AppSidebar() {
|
||||
const {user} = useSessionStore();
|
||||
const {modules} = useModuleStore();
|
||||
|
||||
console.log(user);
|
||||
return (
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarContent>
|
||||
<Header />
|
||||
{moduleActive("production") && <ProductionSideBar />}
|
||||
{moduleActive("logistics") && hasAccess(user, "logistics", "view") && <LogisticsSideBar />}
|
||||
{moduleActive("forklift") && hasAccess(user, "forklift", "view") && <ForkliftSideBar />}
|
||||
{moduleActive("admin") && hasAccess(user, "eom", "view") && <EomSideBar />}
|
||||
{moduleActive("quality") && hasAccess(user, "quality", "view") && <QualitySideBar />}
|
||||
{moduleActive("admin") && hasAccess(user, "admin", "view") && <AdminSideBar />}
|
||||
{moduleActive("logistics") && hasAccess(user, "logistics", modules) && <LogisticsSideBar />}
|
||||
{moduleActive("forklift") && hasAccess(user, "forklift", modules) && <ForkliftSideBar />}
|
||||
{moduleActive("admin") && hasAccess(user, "eom", modules) && <EomSideBar />}
|
||||
{moduleActive("quality") && hasAccess(user, "quality", modules) && <QualitySideBar />}
|
||||
{moduleActive("admin") && hasAccess(user, "admin", modules) && <AdminSideBar />}
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<SidebarTrigger />
|
||||
|
||||
@@ -13,21 +13,25 @@ const items = [
|
||||
title: "Silo Adjustments",
|
||||
url: "#",
|
||||
icon: Cylinder,
|
||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
title: "Bulk orders",
|
||||
url: "#",
|
||||
icon: Truck,
|
||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
title: "Forecast",
|
||||
url: "#",
|
||||
icon: Truck,
|
||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
title: "Ocme cycle counts",
|
||||
url: "#",
|
||||
icon: Package,
|
||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import {create} from "zustand";
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
user_id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
roles: keyof Roles[];
|
||||
role: string;
|
||||
};
|
||||
|
||||
interface Roles {
|
||||
role: string;
|
||||
}
|
||||
|
||||
export type SessionState = {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
|
||||
48
frontend/src/lib/store/useGetRoles.ts
Normal file
48
frontend/src/lib/store/useGetRoles.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {create} from "zustand";
|
||||
import {useSessionStore} from "./sessionStore";
|
||||
//import useSWR from "swr";
|
||||
|
||||
interface Modules {
|
||||
module_id: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
roles: string;
|
||||
add_user: string;
|
||||
add_date: Date;
|
||||
upd_user: string;
|
||||
upd_date: Date;
|
||||
}
|
||||
|
||||
interface SettingState {
|
||||
userRoles: Modules[];
|
||||
|
||||
fetchUserRoles: () => Promise<void>;
|
||||
setUserRoles: (userRoles: Modules[]) => void;
|
||||
}
|
||||
interface FetchModulesResponse {
|
||||
data: Modules[];
|
||||
}
|
||||
|
||||
export const useModuleStore = create<SettingState>()((set) => ({
|
||||
userRoles: [],
|
||||
setUserRoles: (userRoles) => set({userRoles}),
|
||||
fetchUserRoles: async () => {
|
||||
try {
|
||||
//const response = await axios.get<{data: Setting[]}>(`${process.env.NEXT_PUBLIC_URL}/api/settings/client`);
|
||||
const {token} = useSessionStore();
|
||||
const response = await fetch(`/api/auth/getuseraccess`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authentication: `Beaer ${token}`,
|
||||
// You can add other headers here if necessary
|
||||
},
|
||||
});
|
||||
const data: FetchModulesResponse = await response.json();
|
||||
//console.log(data);
|
||||
set({userRoles: data.data});
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch settings:", error);
|
||||
}
|
||||
},
|
||||
}));
|
||||
@@ -1,16 +1,17 @@
|
||||
import {Modules} from "@/types/modules";
|
||||
import {create} from "zustand";
|
||||
//import useSWR from "swr";
|
||||
|
||||
interface Modules {
|
||||
module_id: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
roles: string;
|
||||
add_user: string;
|
||||
add_date: Date;
|
||||
upd_user: string;
|
||||
upd_date: Date;
|
||||
}
|
||||
// interface Modules {
|
||||
// module_id: string;
|
||||
// name: string;
|
||||
// active: boolean;
|
||||
// roles: string;
|
||||
// add_user: string;
|
||||
// add_date: Date;
|
||||
// upd_user: string;
|
||||
// upd_date: Date;
|
||||
// }
|
||||
|
||||
interface SettingState {
|
||||
modules: Modules[];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {StrictMode} from "react";
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import "./styles.css";
|
||||
import {RouterProvider, createRouter} from "@tanstack/react-router";
|
||||
@@ -19,15 +19,23 @@ declare module "@tanstack/react-router" {
|
||||
}
|
||||
}
|
||||
|
||||
// Render the app
|
||||
const rootElement = document.getElementById("root")!;
|
||||
if (!rootElement.innerHTML) {
|
||||
const root = ReactDOM.createRoot(rootElement);
|
||||
root.render(
|
||||
<StrictMode>
|
||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<RouterProvider router={router} />
|
||||
</QueryClientProvider>
|
||||
</StrictMode>
|
||||
</React.StrictMode>
|
||||
);
|
||||
}
|
||||
|
||||
// // Render the app
|
||||
// const rootElement = document.getElementById("root")!;
|
||||
// if (!rootElement.innerHTML) {
|
||||
// const root = ReactDOM.createRoot(rootElement);
|
||||
// root.render(
|
||||
// <StrictMode>
|
||||
// <QueryClientProvider client={queryClient}>
|
||||
// <RouterProvider router={router} />
|
||||
// </QueryClientProvider>
|
||||
// </StrictMode>
|
||||
// );
|
||||
// }
|
||||
|
||||
10
frontend/src/types/modules.ts
Normal file
10
frontend/src/types/modules.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface Modules {
|
||||
module_id: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
roles: string;
|
||||
add_User: string;
|
||||
add_Date: Date;
|
||||
upd_user: string;
|
||||
upd_date: Date;
|
||||
}
|
||||
@@ -19,5 +19,5 @@ import {useModuleStore} from "../lib/store/useModuleStore";
|
||||
export function moduleActive(moduleName: string): boolean {
|
||||
const {modules} = useModuleStore();
|
||||
const module = modules.find((m: any) => m.name === moduleName);
|
||||
return module ? module.active : false;
|
||||
return module ? true : false;
|
||||
}
|
||||
|
||||
@@ -1,52 +1,25 @@
|
||||
interface User {
|
||||
id: number;
|
||||
import {Modules} from "@/types/modules";
|
||||
|
||||
type User = {
|
||||
user_id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
role: keyof Roles;
|
||||
}
|
||||
roles: keyof Roles[];
|
||||
role: string;
|
||||
};
|
||||
|
||||
interface Roles {
|
||||
[roleName: string]: RolePermissions;
|
||||
role: string;
|
||||
}
|
||||
|
||||
interface RolePermissions {
|
||||
[moduleName: string]: Feature[];
|
||||
}
|
||||
|
||||
type Feature = string;
|
||||
|
||||
const rolePermissions: Roles = {
|
||||
admin: {
|
||||
production: ["view", "manage", "update", "admin"],
|
||||
logistics: ["view", "manage", "update", "admin"],
|
||||
quality: ["view", "request", "manage", "update", "admin"],
|
||||
forklift: ["view", "manage", "update", "admin"],
|
||||
admin: ["view", "view_logs", "manage", "update", "admin"],
|
||||
},
|
||||
manager: {
|
||||
production: ["view", "manage"],
|
||||
logistics: ["view", "manage"],
|
||||
quality: ["view", "manage"],
|
||||
forklift: ["view", "manage"],
|
||||
admin: ["view_logs"],
|
||||
},
|
||||
supervisor: {
|
||||
production: ["view", "update"],
|
||||
logistics: ["view", "update"],
|
||||
quality: ["view", "update"],
|
||||
forklift: ["view"],
|
||||
admin: [],
|
||||
},
|
||||
user: {
|
||||
production: ["view"],
|
||||
logistics: ["view"],
|
||||
quality: ["view"],
|
||||
forklift: [],
|
||||
admin: [],
|
||||
},
|
||||
};
|
||||
|
||||
// user will need access to the module.
|
||||
// users role will determine there visual access
|
||||
export function hasAccess(user: User | null, moduleName: string, feature: Feature): boolean {
|
||||
return user?.role ? rolePermissions[user.role]?.[moduleName]?.includes(feature) || false : false;
|
||||
export function hasAccess(user: User | null, moduleName: string | null, modules: Modules[]): boolean {
|
||||
// get the modules for the id
|
||||
const filteredModule = modules?.filter((f) => f.name === moduleName);
|
||||
console.log(filteredModule);
|
||||
// userroles and filter out by the module id,
|
||||
|
||||
console.log(user);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import path from "path";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss(), TanStackRouterVite({autoCodeSplitting: true})],
|
||||
plugins: [react(), tailwindcss(), TanStackRouterVite({target: "react", autoCodeSplitting: true})],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
|
||||
4598
package-lock.json
generated
4598
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@@ -4,13 +4,13 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "concurrently -n \"server,frontend\" -c \"#007755,#2f6da3\" \"npm run dev:server\" \"cd frontend && npm run dev\"",
|
||||
"dev:server": "dotenvx run -f .env -- tsx watch server/src/index.ts",
|
||||
"dev:server": "dotenvx run -f .env -- tsx watch server/index.ts",
|
||||
"dev:frontend": "cd frontend && npm run dev",
|
||||
"build": "npm run build:server && npm run build:frontend",
|
||||
"build:server": "cd server && npm run build",
|
||||
"build:server": "rimraf dist && tsc --build",
|
||||
"build:frontend": "cd frontend && npm run build",
|
||||
"start": "npm run start:server",
|
||||
"start:server": "cd server && npm start",
|
||||
"start:server": "dotenvx run -f .env -- node dist/server/index.js",
|
||||
"db:generate": "npx drizzle-kit generate",
|
||||
"db:migrate": "npx drizzle-kit push",
|
||||
"deploy": "standard-version --conventional-commits",
|
||||
@@ -18,9 +18,19 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@dotenvx/dotenvx": "^1.38.3",
|
||||
"hono": "^4.7.2",
|
||||
"@hono/node-server": "^1.13.8",
|
||||
"@hono/zod-openapi": "^0.18.4",
|
||||
"@scalar/hono-api-reference": "^0.5.175",
|
||||
"@types/jsonwebtoken": "^9.0.8",
|
||||
"axios": "^1.7.9",
|
||||
"bcrypt": "^5.1.1",
|
||||
"compression": "^1.8.0",
|
||||
"cookie": "^1.0.2",
|
||||
"date-fns": "^4.1.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"drizzle-orm": "^0.39.3",
|
||||
"drizzle-zod": "^0.7.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"pg": "^8.13.3",
|
||||
"postgres": "^3.4.5",
|
||||
"zod": "^3.24.2"
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
```
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
```
|
||||
open http://localhost:3000
|
||||
```
|
||||
@@ -4,8 +4,8 @@ import {serveStatic} from "@hono/node-server/serve-static";
|
||||
import {logger} from "hono/logger";
|
||||
import {cors} from "hono/cors";
|
||||
|
||||
import {db} from "../../database/dbclient.js";
|
||||
import {modules} from "../../database/schema/modules.js";
|
||||
import {db} from "../database/dbclient.js";
|
||||
import {modules} from "../database/schema/modules.js";
|
||||
|
||||
// custom routes
|
||||
import scalar from "./services/general/route/scalar.js";
|
||||
@@ -44,7 +44,7 @@ const routes = [
|
||||
system,
|
||||
] as const;
|
||||
|
||||
routes.forEach((route) => {
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/api/", route);
|
||||
});
|
||||
|
||||
@@ -57,8 +57,8 @@ app.all("/ocme/*", async (c) => {
|
||||
});
|
||||
|
||||
// front end static files
|
||||
app.get("*", serveStatic({root: "../frontend/dist"}));
|
||||
app.get("*", serveStatic({path: "../frontend/dist/index.html"}));
|
||||
app.use("/*", serveStatic({root: "./frontend/dist"}));
|
||||
app.use("*", serveStatic({path: "./frontend/dist/index.html"}));
|
||||
|
||||
serve(
|
||||
{
|
||||
@@ -69,3 +69,5 @@ serve(
|
||||
console.log(`Server is running on http://localhost:${info.port}`);
|
||||
}
|
||||
);
|
||||
|
||||
export type AppRoutes = typeof appRoutes;
|
||||
2123
server/package-lock.json
generated
2123
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"name": "server",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "dotenvx run -f ../.env -- tsx watch src/index.ts",
|
||||
"build": "rimraf dist && tsc --build",
|
||||
"start": "dotenvx run node dist/server/src/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hono/node-server": "^1.13.8",
|
||||
"@dotenvx/dotenvx": "^1.35.0",
|
||||
"@hono/zod-openapi": "^0.18.4",
|
||||
"@scalar/hono-api-reference": "^0.5.175",
|
||||
"@types/jsonwebtoken": "^9.0.8",
|
||||
"axios": "^1.7.9",
|
||||
"bcrypt": "^5.1.1",
|
||||
"compression": "^1.8.0",
|
||||
"cookie": "^1.0.2",
|
||||
"date-fns": "^4.1.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"drizzle-orm": "^0.39.3",
|
||||
"drizzle-zod": "^0.7.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"pg": "^8.13.3",
|
||||
"postgres": "^3.4.5",
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.7.3"
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,16 @@ import {OpenAPIHono} from "@hono/zod-openapi";
|
||||
import login from "./routes/login.js";
|
||||
import register from "./routes/register.js";
|
||||
import session from "./routes/session.js";
|
||||
import getAccess from "./routes/getUserRoles.js";
|
||||
import {authMiddleware} from "./middleware/authMiddleware.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
app.route("auth/login", login);
|
||||
app.route("auth/register", register);
|
||||
app.route("auth/session", session);
|
||||
|
||||
// required to login
|
||||
app.use("auth/getuseraccess", authMiddleware);
|
||||
app.route("/auth/getuseraccess", getAccess);
|
||||
|
||||
export default app;
|
||||
@@ -4,8 +4,8 @@ in the login route we attach it to user under roles.
|
||||
*/
|
||||
|
||||
import {eq} from "drizzle-orm";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {userRoles} from "../../../../../database/schema/userRoles.js";
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {userRoles} from "../../../../database/schema/userRoles.js";
|
||||
|
||||
export const roleCheck = async (user_id: any) => {
|
||||
// get the user roles by the user_id
|
||||
@@ -1,6 +1,6 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {users} from "../../../../../database/schema/users.js";
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {users} from "../../../../database/schema/users.js";
|
||||
import {eq, sql} from "drizzle-orm";
|
||||
import {checkPassword} from "../utils/checkPassword.js";
|
||||
import {roleCheck} from "./getUserAccess.js";
|
||||
@@ -1,5 +1,7 @@
|
||||
import {type MiddlewareHandler} from "hono";
|
||||
import {sign, verify} from "jsonwebtoken";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
const {sign, verify} = jwt;
|
||||
|
||||
export const authMiddleware: MiddlewareHandler = async (c, next) => {
|
||||
const authHeader = c.req.header("Authorization");
|
||||
31
server/services/auth/routes/getUserRoles.ts
Normal file
31
server/services/auth/routes/getUserRoles.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional().openapi({example: "User Created"}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["Auth"],
|
||||
summary: "Returns the useraccess table",
|
||||
method: "get",
|
||||
path: "/",
|
||||
|
||||
responses: {
|
||||
200: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "Retrieve the user",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
// apit hit
|
||||
apiHit(c, {endpoint: "api/auth/register"});
|
||||
return c.json({message: "UserRoles coming over"});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
@@ -1,6 +1,6 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {users} from "../../../../../database/schema/users.js";
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {users} from "../../../../database/schema/users.js";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {createPassword} from "../utils/createPassword.js";
|
||||
import {eq} from "drizzle-orm";
|
||||
@@ -1,6 +1,6 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {modules} from "../../../../../database/schema/modules.js";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {modules} from "../../../../database/schema/modules.js";
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {eq} from "drizzle-orm";
|
||||
|
||||
// Define the request body schema
|
||||
@@ -12,5 +12,5 @@
|
||||
"outDir": "./dist",
|
||||
"removeComments": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
"exclude": ["node_modules", "frontend"]
|
||||
}
|
||||
Reference in New Issue
Block a user