Arjix
Arjix
Explore posts from servers
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
Keep It Simple Silly + Don't Repeat Yourself
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
I think a combination of KISS and DRY are perfect for hono
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
(I didn't chain everything together cause I don't use the rpc)
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
No description
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
if it has to do with validation, I either inline the zod schema, or place it in a separate file, depends on how re-usable the schema is
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
if it has to do with db, I have made a repository for it
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
depends
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
and I design my middleware to be idempotent, so I can call them multiple times across multiple controllers w/o care TL;DR, design your middleware to do the heavy lifting once
export type UserSession = (Omit<SessionObject, 'user'> & { user: UserObject });
export type AuthVariables = { session: UserSession | null };

export const auth = createMiddleware<{ Variables: AuthVariables }>(
async (ctx, next) => {
// HERE
if (ctx.get('session')) return await next();
// ^^ HERE we gain idemptotance

const sessionHandler = container.resolve(tokens.SessionHandler);

const headerToken = ctx.req.header('token');
const cookieToken = getCookie(ctx, 'token');

const token = cookieToken ?? headerToken;

const session = token ? await sessionHandler.touch(token) : null;

if (session) {
setCookie(ctx, 'token', session.token, {
// secure: true,
httpOnly: true,
expires: session.expires
});
}

ctx.set('session', session);
return await next();
}
);
export type UserSession = (Omit<SessionObject, 'user'> & { user: UserObject });
export type AuthVariables = { session: UserSession | null };

export const auth = createMiddleware<{ Variables: AuthVariables }>(
async (ctx, next) => {
// HERE
if (ctx.get('session')) return await next();
// ^^ HERE we gain idemptotance

const sessionHandler = container.resolve(tokens.SessionHandler);

const headerToken = ctx.req.header('token');
const cookieToken = getCookie(ctx, 'token');

const token = cookieToken ?? headerToken;

const session = token ? await sessionHandler.touch(token) : null;

if (session) {
setCookie(ctx, 'token', session.token, {
// secure: true,
httpOnly: true,
expires: session.expires
});
}

ctx.set('session', session);
return await next();
}
);
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
src/controllers/AuthController.ts
export const AuthController = new Hono().basePath("/auth")
.post("/login", async (ctx) => {
// do stuff
})
.post("/logout", async (ctx) => {
// do stuff
});
export const AuthController = new Hono().basePath("/auth")
.post("/login", async (ctx) => {
// do stuff
})
.post("/logout", async (ctx) => {
// do stuff
});
src/index.ts
const app = new Hono()
.route("/", AuthController)
// ...other controllers

export type APP = typeof app;
const app = new Hono()
.route("/", AuthController)
// ...other controllers

export type APP = typeof app;
is how I'd shape a controller
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
my first backend was in ASP.NET, so controllers for me are way too different from the controllers you imagine
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
I think your coding background defines that ngl (not talking about performance lol)
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
sums it up pretty well
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
32 replies
HHono
Created by Barzi Ahmed on 4/9/2025 in #help
Which Hono Router Should I Use in This Case?
TrieRouter splits the url in segments, and makes a tree out of them so the order of the routes does not matter
7 replies
HHono
Created by Barzi Ahmed on 4/9/2025 in #help
Which Hono Router Should I Use in This Case?
I've implemented a trie-router myself in kotlin, that's why I said it would most likely be the one you want
7 replies
HHono
Created by Barzi Ahmed on 4/9/2025 in #help
Which Hono Router Should I Use in This Case?
trierouter will match the pathname exactly iirc
7 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
(even though I fail to see how that is a controller, coming from an ASP.NET background)
32 replies
HHono
Created by Kalpak on 4/9/2025 in #help
zValidator c.req.valid("form") type error
the docs discourage RoR-like controllers like yours for the exact issues you are facing
32 replies
HHono
Created by WAAYZZz 🍀 on 4/7/2025 in #help
exemple for zod-openapi + rpc
PS: for openapi generation, it will only include routes that have the middleware describeRoute, routes w/o it won't show up on swagger for example
44 replies
HHono
Created by WAAYZZz 🍀 on 4/7/2025 in #help
exemple for zod-openapi + rpc
It'll just work
44 replies