CrisOG
CrisOG
Explore posts from servers
HHono
Created by CrisOG on 8/31/2024 in #help
Middleware errors are not being returned in response type
I have a user route using an auth middleware,
export const usersRouter = new Hono()
.use(authorize)
.get('/', async (c) => {
const user = await User.getByUserID(c.var.auth.userID);

if (!user) {
return c.json({ error: 'User not found' }, 404);
}

return c.json(user, 200);
})
export const usersRouter = new Hono()
.use(authorize)
.get('/', async (c) => {
const user = await User.getByUserID(c.var.auth.userID);

if (!user) {
return c.json({ error: 'User not found' }, 404);
}

return c.json(user, 200);
})
And this is the auth middleware,
import { createMiddleware } from 'hono/factory';
import { lucia } from './lucia';

export const authorize = createMiddleware<{
Variables: {
auth: {
userID: string;
sessionID: string;
};
};
}>(async (c, next) => {
const cookieHeader = c.req.header('Cookie');

if (!cookieHeader) {
return c.json({ error: 'Unauthorized' }, 401);
}
// Code omitted ...
});
import { createMiddleware } from 'hono/factory';
import { lucia } from './lucia';

export const authorize = createMiddleware<{
Variables: {
auth: {
userID: string;
sessionID: string;
};
};
}>(async (c, next) => {
const cookieHeader = c.req.header('Cookie');

if (!cookieHeader) {
return c.json({ error: 'Unauthorized' }, 401);
}
// Code omitted ...
});
But, the response type has only 2 possible status code.
Argument of type '401' is not assignable to parameter of type '200 | 404'.ts(2345)
Argument of type '401' is not assignable to parameter of type '200 | 404'.ts(2345)
This is a problem because I write some tests that expect this error code when accessing an auth protected route without auth.
2 replies
RRailway
Created by CrisOG on 5/2/2024 in #✋|help
PCI-DSS Compliance
I'm building a product and the payment gateway demands that my app is PCI-DSS compliant, but most of the criteria for it seems to be server security oriented + networking. If I use Railway for production, can I just say I'm PCI-DSS compliant?
6 replies
DTDrizzle Team
Created by CrisOG on 2/4/2024 in #help
sql.placeholder not working for pg array of strings
const create = db
.insert(eventTable)
.values({
title: sql.placeholder('title'),
images: sql.placeholder('images')
})
.returning()
.prepare('createEvent');
const create = db
.insert(eventTable)
.values({
title: sql.placeholder('title'),
images: sql.placeholder('images')
})
.returning()
.prepare('createEvent');
export const eventTable = pgTable('event', {
id: uuid('id').primaryKey().defaultRandom(),
title: text('title').notNull(),
images: text('images').array(),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow()
});
export const eventTable = pgTable('event', {
id: uuid('id').primaryKey().defaultRandom(),
title: text('title').notNull(),
images: text('images').array(),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow()
});
This fails at start time (not even until calling the DB, right after starting the server) with the following error:
TypeError: value.map is not a function
at PgArray.mapToDriverValue (file:///project/node_modules/drizzle-orm/pg-core/columns/common.js:93:21)
at file:///project/node_modules/drizzle-orm/sql/sql.js:119:73
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:91:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:94:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:52:26
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at SQL.toQuery (file:///project/node_modules/drizzle-orm/sql/sql.js:51:19)
at PgDialect.sqlToQuery (file:///project/node_modules/drizzle-orm/pg-core/dialect.js:362:17)
at file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:124:53
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at QueryPromise._prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:123:19)
at QueryPromise.prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:128:17)
at /project/src/server/db/models/event.ts:17:4
at async instantiateModule (file:///project/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:50861:9)
TypeError: value.map is not a function
at PgArray.mapToDriverValue (file:///project/node_modules/drizzle-orm/pg-core/columns/common.js:93:21)
at file:///project/node_modules/drizzle-orm/sql/sql.js:119:73
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:91:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:94:21
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///project/node_modules/drizzle-orm/sql/sql.js:72:32)
at file:///project/node_modules/drizzle-orm/sql/sql.js:52:26
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at SQL.toQuery (file:///project/node_modules/drizzle-orm/sql/sql.js:51:19)
at PgDialect.sqlToQuery (file:///project/node_modules/drizzle-orm/pg-core/dialect.js:362:17)
at file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:124:53
at Object.startActiveSpan (file:///project/node_modules/drizzle-orm/tracing.js:8:14)
at QueryPromise._prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:123:19)
at QueryPromise.prepare (file:///project/node_modules/drizzle-orm/pg-core/query-builders/insert.js:128:17)
at /project/src/server/db/models/event.ts:17:4
at async instantiateModule (file:///project/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:50861:9)
5 replies
DTDrizzle Team
Created by CrisOG on 1/31/2024 in #help
Placeholder does not work properly with update
const update = db
.update(userTable)
.set({ name: sql.placeholder('name') })
.where(eq(userTable.id, sql.placeholder('id')))
.prepare('updateUser');
const update = db
.update(userTable)
.set({ name: sql.placeholder('name') })
.where(eq(userTable.id, sql.placeholder('id')))
.prepare('updateUser');
Is there a workaround to this?
8 replies