()({
+export const Route = createRootRoute({
component: () => {
+ const sidebarState = Cookies.get("sidebar_state") === "true";
+
return (
<>
-
-
- Home
- {" "}
-
- About
-
-
- dashboard
-
-
- {({isActive}) => <>Profile {isActive && "~"}>}
-
-
- {({isActive}) => <>OCP {isActive && "~"}>}
-
-
-
-
+
+
+
+
+
+
+
-
+
>
);
},
diff --git a/frontend/src/routes/_auth.tsx b/frontend/src/routes/_auth.tsx
index 43aa3c1..a3723d0 100644
--- a/frontend/src/routes/_auth.tsx
+++ b/frontend/src/routes/_auth.tsx
@@ -2,8 +2,9 @@ import {createFileRoute, redirect} from "@tanstack/react-router";
// src/routes/_authenticated.tsx
export const Route = createFileRoute("/_auth")({
- beforeLoad: async ({context}) => {
- if (!context.sessionType.session) {
+ beforeLoad: async () => {
+ const auth = localStorage.getItem("auth_token");
+ if (!auth) {
throw redirect({
to: "/",
});
diff --git a/frontend/src/routes/_auth/dashboard.tsx b/frontend/src/routes/_auth/dashboard.tsx
index 09dd879..03e8530 100644
--- a/frontend/src/routes/_auth/dashboard.tsx
+++ b/frontend/src/routes/_auth/dashboard.tsx
@@ -1,9 +1,16 @@
-import { createFileRoute } from '@tanstack/react-router'
+import {createFileRoute} from "@tanstack/react-router";
+import {Button} from "../../components/ui/button";
+import {useLogout} from "../../lib/hooks/useLogout";
-export const Route = createFileRoute('/_auth/dashboard')({
- component: RouteComponent,
-})
+export const Route = createFileRoute("/_auth/dashboard")({
+ component: RouteComponent,
+});
function RouteComponent() {
- return Hello "/_auth/dashboard"!
+ const logout = useLogout();
+ return (
+
+ Hello "/_auth/dashboard"!
+
+ );
}
diff --git a/frontend/src/routes/index.tsx b/frontend/src/routes/index.tsx
index 6074078..12ceb84 100644
--- a/frontend/src/routes/index.tsx
+++ b/frontend/src/routes/index.tsx
@@ -3,6 +3,7 @@ import LoginForm from "../components/auth/LoginForm";
import {Button} from "../components/ui/button";
import {useLogout} from "../lib/hooks/useLogout";
import {useSession} from "../lib/hooks/useSession";
+import {useSessionStore} from "../lib/store/sessionStore";
export const Route = createFileRoute("/")({
component: Index,
@@ -10,20 +11,20 @@ export const Route = createFileRoute("/")({
function Index() {
const {session} = useSession();
+ const {user} = useSessionStore();
const logout = useLogout();
return (
-
Welcome Home!
-
-
- {session ? (
- <>
- {" "}
- >
- ) : (
-
- )}
-
+ {session ? (
+ <>
+
Welcome Home {user?.username}
+
Your current role is: {user?.role}
+
+
{" "}
+ >
+ ) : (
+
+ )}
);
}
diff --git a/frontend/src/styles.css b/frontend/src/styles.css
index 0a1f462..e68c19c 100644
--- a/frontend/src/styles.css
+++ b/frontend/src/styles.css
@@ -30,6 +30,14 @@
--chart-4: hsl(43 74% 66%);
--chart-5: hsl(27 87% 67%);
--radius: 0.6rem;
+ --sidebar: hsl(0 0% 98%);
+ --sidebar-foreground: hsl(240 5.3% 26.1%);
+ --sidebar-primary: hsl(240 5.9% 10%);
+ --sidebar-primary-foreground: hsl(0 0% 98%);
+ --sidebar-accent: hsl(240 4.8% 95.9%);
+ --sidebar-accent-foreground: hsl(240 5.9% 10%);
+ --sidebar-border: hsl(220 13% 91%);
+ --sidebar-ring: hsl(217.2 91.2% 59.8%);
}
.dark {
@@ -57,6 +65,14 @@
--chart-3: hsl(30 80% 55%);
--chart-4: hsl(280 65% 60%);
--chart-5: hsl(340 75% 55%);
+ --sidebar: hsl(240 5.9% 10%);
+ --sidebar-foreground: hsl(240 4.8% 95.9%);
+ --sidebar-primary: hsl(224.3 76.3% 48%);
+ --sidebar-primary-foreground: hsl(0 0% 100%);
+ --sidebar-accent: hsl(240 3.7% 15.9%);
+ --sidebar-accent-foreground: hsl(240 4.8% 95.9%);
+ --sidebar-border: hsl(240 3.7% 15.9%);
+ --sidebar-ring: hsl(217.2 91.2% 59.8%);
}
@theme inline {
@@ -88,6 +104,14 @@
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
+ --color-sidebar-ring: var(--sidebar-ring);
+ --color-sidebar-border: var(--sidebar-border);
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
+ --color-sidebar-accent: var(--sidebar-accent);
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
+ --color-sidebar-primary: var(--sidebar-primary);
+ --color-sidebar-foreground: var(--sidebar-foreground);
+ --color-sidebar: var(--sidebar);
}
@layer base {
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index fec8c8e..0ceb734 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -1,13 +1,10 @@
{
- "files": [],
- "references": [
- { "path": "./tsconfig.app.json" },
- { "path": "./tsconfig.node.json" }
- ],
- "compilerOptions": {
- "baseUrl": ".",
- "paths": {
- "@/*": ["./src/*"]
+ "files": [],
+ "references": [{"path": "./tsconfig.app.json"}, {"path": "./tsconfig.node.json"}],
+ "compilerOptions": {
+ // "baseUrl": ".",
+ "paths": {
+ "@/*": ["./src/*"]
+ }
}
- }
}
diff --git a/package.json b/package.json
index 9e446d0..7ff2a31 100644
--- a/package.json
+++ b/package.json
@@ -30,17 +30,20 @@
"compression": "^1.8.0",
"cookie": "^1.0.2",
"date-fns": "^4.1.0",
+ "drizzle-orm": "^0.39.3",
+ "drizzle-zod": "^0.7.0",
"hono": "^4.7.1",
"http-proxy-middleware": "^3.0.3",
"jsonwebtoken": "^9.0.2",
"zod": "^3.24.2"
},
"devDependencies": {
+ "@types/js-cookie": "^3.0.6",
+ "concurrently": "^9.1.2",
"cz-conventional-changelog": "^3.3.0",
"rimraf": "^6.0.1",
"standard-version": "^9.5.0",
- "typescript": "~5.7.3",
- "concurrently": "^9.1.2"
+ "typescript": "~5.7.3"
},
"config": {
"commitizen": {
diff --git a/server/src/services/auth/controllers/login.ts b/server/src/services/auth/controllers/login.ts
index cd594a6..0031f87 100644
--- a/server/src/services/auth/controllers/login.ts
+++ b/server/src/services/auth/controllers/login.ts
@@ -5,21 +5,24 @@ import {sign, verify} from "jsonwebtoken";
*/
const fakeUsers = [
- {id: 1, username: "admin", password: "password123"},
- {id: 2, username: "user", password: "password123"},
- {id: 3, username: "user2", password: "password123"},
+ {id: 1, username: "admin", password: "password123", role: "admin"},
+ {id: 2, username: "user", password: "pass", role: "user"},
+ {id: 3, username: "user2", password: "password123", role: "user"},
];
-export function login(username: string, password: string): {token: string; user: {id: number; username: string}} {
+export function login(
+ username: string,
+ password: string
+): {token: string; user: {id: number; username: string; role: string}} {
const user = fakeUsers.find((u) => u.username === username && u.password === password);
if (!user) {
throw new Error("Invalid credentials");
}
// Create a JWT
- const token = sign({userId: user?.id, username: user?.username}, process.env.JWT_SECRET, {
+ const token = sign({user}, process.env.JWT_SECRET, {
expiresIn: process.env.JWT_EXPIRES,
});
- return {token, user: {id: user?.id, username: user.username}};
+ return {token, user: {id: user?.id, username: user.username, role: user.role}};
}
diff --git a/server/src/services/auth/routes/session.ts b/server/src/services/auth/routes/session.ts
index cc7f186..7c2dbfd 100644
--- a/server/src/services/auth/routes/session.ts
+++ b/server/src/services/auth/routes/session.ts
@@ -40,7 +40,7 @@ session.openapi(route, async (c) => {
try {
const payload = await verify(token, JWT_SECRET);
console.log(payload);
- return c.json({token});
+ return c.json({data: {token, user: payload.user}});
} catch (err) {
return c.json({error: "Invalid or expired token"}, 401);
}