Strange error

Hi, I'm trying to create something with HonoJS, CloudFlare Workers and D1 (with Prisma). I just want to temporarily lock the user, only I run into this strange problem. Code:
import { Hono } from "hono";
import { logger } from 'hono/logger'

import { fromHono } from "chanfana";
import { EventCreate } from "routes/event/EventCreate";

type Bindings = {
DB: D1Database
}

const app = new Hono<{ Bindings: Bindings }>();

app.use(logger())

app.use(async (c, next) => {
c.user = { id: 1 }
await next();
}
)

const openapi = fromHono(app, {
docs_url: "/docs",
});

openapi.post("/api/event", EventCreate);

export default app;
import { Hono } from "hono";
import { logger } from 'hono/logger'

import { fromHono } from "chanfana";
import { EventCreate } from "routes/event/EventCreate";

type Bindings = {
DB: D1Database
}

const app = new Hono<{ Bindings: Bindings }>();

app.use(logger())

app.use(async (c, next) => {
c.user = { id: 1 }
await next();
}
)

const openapi = fromHono(app, {
docs_url: "/docs",
});

openapi.post("/api/event", EventCreate);

export default app;
Error that vsc shows: Property 'user' does not exist on type 'Context<{ Bindings: Bindings; }, never, {}>'.ts(2339) Thanks for any help!
2 Replies
gwapes
gwapes2w ago
You may want to use something like <{ Bindings: …, Variables: { user: { id: number }}> Then c.set('user', { id: 1 }) Then whenever you want to get it c.get('user') Lmk if there’s anything wrong, syntax may be wrong since I’m on phone
Tiebienotjuh
TiebienotjuhOP2w ago
Okay thanks!
Want results from more Discord servers?
Add your server