Move hono env to separate type
This commit is contained in:
parent
af2c452e64
commit
71d1d539fc
|
|
@ -12,14 +12,11 @@ import dashboardRoutes from "./routes/dashboard/routes";
|
||||||
import rolesRoute from "./routes/roles/route";
|
import rolesRoute from "./routes/roles/route";
|
||||||
import { logger } from "hono/logger";
|
import { logger } from "hono/logger";
|
||||||
import DashboardError from "./errors/DashboardError";
|
import DashboardError from "./errors/DashboardError";
|
||||||
|
import HonoEnv from "./types/HonoEnv";
|
||||||
|
|
||||||
configDotenv();
|
configDotenv();
|
||||||
|
|
||||||
export type HonoVariables = {
|
const app = new Hono<HonoEnv>();
|
||||||
uid?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const app = new Hono<{ Variables: HonoVariables }>();
|
|
||||||
|
|
||||||
const routes = app
|
const routes = app
|
||||||
.use(logger())
|
.use(logger())
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import { Hono } from "hono";
|
||||||
import { deleteCookie } from "hono/cookie";
|
import { deleteCookie } from "hono/cookie";
|
||||||
import { HTTPException } from "hono/http-exception";
|
import { HTTPException } from "hono/http-exception";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { HonoVariables } from "../..";
|
|
||||||
import db from "../../drizzle";
|
import db from "../../drizzle";
|
||||||
import { users } from "../../drizzle/schema/users";
|
import { users } from "../../drizzle/schema/users";
|
||||||
import { checkPassword } from "../../utils/passwordUtils";
|
import { checkPassword } from "../../utils/passwordUtils";
|
||||||
|
|
@ -15,8 +14,9 @@ import {
|
||||||
} from "../../utils/authUtils";
|
} from "../../utils/authUtils";
|
||||||
import { rolesSchema } from "../../drizzle/schema/roles";
|
import { rolesSchema } from "../../drizzle/schema/roles";
|
||||||
import { rolesToUsers } from "../../drizzle/schema/rolesToUsers";
|
import { rolesToUsers } from "../../drizzle/schema/rolesToUsers";
|
||||||
|
import HonoEnv from "../../types/HonoEnv";
|
||||||
|
|
||||||
const authRoutes = new Hono<{ Variables: HonoVariables }>()
|
const authRoutes = new Hono<HonoEnv>()
|
||||||
.post(
|
.post(
|
||||||
"/login",
|
"/login",
|
||||||
zValidator(
|
zValidator(
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ import { SidebarMenu } from "../../types";
|
||||||
import { forbidden } from "../../utils/httpErrors";
|
import { forbidden } from "../../utils/httpErrors";
|
||||||
import { and, eq, or } from "drizzle-orm";
|
import { and, eq, or } from "drizzle-orm";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { HonoVariables } from "../..";
|
import HonoEnv from "../../types/HonoEnv";
|
||||||
|
|
||||||
const router = new Hono<{ Variables: HonoVariables }>();
|
const router = new Hono<HonoEnv>();
|
||||||
|
|
||||||
const dashboardRoutes = router.get("/getSidebarItems", async (c) => {
|
const dashboardRoutes = router.get("/getSidebarItems", async (c) => {
|
||||||
const uid = c.var.uid;
|
const uid = c.var.uid;
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ import { z } from "zod";
|
||||||
import { HTTPException } from "hono/http-exception";
|
import { HTTPException } from "hono/http-exception";
|
||||||
import db from "../../drizzle";
|
import db from "../../drizzle";
|
||||||
import { users } from "../../drizzle/schema/users";
|
import { users } from "../../drizzle/schema/users";
|
||||||
import { HonoVariables } from "../..";
|
|
||||||
import { hashPassword } from "../../utils/passwordUtils";
|
import { hashPassword } from "../../utils/passwordUtils";
|
||||||
import { rolesToUsers } from "../../drizzle/schema/rolesToUsers";
|
import { rolesToUsers } from "../../drizzle/schema/rolesToUsers";
|
||||||
import { rolesSchema } from "../../drizzle/schema/roles";
|
import { rolesSchema } from "../../drizzle/schema/roles";
|
||||||
|
import HonoEnv from "../../types/HonoEnv";
|
||||||
|
|
||||||
const userFormSchema = z.object({
|
const userFormSchema = z.object({
|
||||||
name: z.string().min(1).max(255),
|
name: z.string().min(1).max(255),
|
||||||
|
|
@ -40,7 +40,7 @@ const userUpdateSchema = userFormSchema.extend({
|
||||||
password: z.string().min(6).optional().or(z.literal("")),
|
password: z.string().min(6).optional().or(z.literal("")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const usersRoute = new Hono<{ Variables: HonoVariables }>()
|
const usersRoute = new Hono<HonoEnv>()
|
||||||
.use(async (c, next) => {
|
.use(async (c, next) => {
|
||||||
const uid = c.get("uid");
|
const uid = c.get("uid");
|
||||||
|
|
||||||
|
|
|
||||||
7
apps/backend/src/types/HonoEnv.d.ts
vendored
Normal file
7
apps/backend/src/types/HonoEnv.d.ts
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
type HonoEnv = {
|
||||||
|
Variables: {
|
||||||
|
uid?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default HonoEnv;
|
||||||
Loading…
Reference in New Issue
Block a user