iEmix
iEmix
HHono
Created by iEmix on 8/13/2024 in #help
How to add custom message to error Bearer Auth
My solution is working now, but I'm not sure if it's the best approach
export const jwt = bearerAuth({
verifyToken: async (accessToken: string, c: AppContext): Promise<boolean> => {
try {
const jwtPayload: JWTPayload = await verifyAccessToken(accessToken);
c.set('user', jwtPayload.user as AuthUser);
return true;
} catch (err) {
throw new Error(err instanceof JwtTokenExpired ? 'Expired JWT Token' : 'Authentication failed');
}
},
});

export const auth: MiddlewareHandler = async (c: AppContext, next: Next): Promise<any> => {
try {
await jwt(c, next);
} catch (e: any) {
return c.json({error: e.message && e.message.length > 0 ? e.message : 'Authentication failed'}, 401);
}
};
export const jwt = bearerAuth({
verifyToken: async (accessToken: string, c: AppContext): Promise<boolean> => {
try {
const jwtPayload: JWTPayload = await verifyAccessToken(accessToken);
c.set('user', jwtPayload.user as AuthUser);
return true;
} catch (err) {
throw new Error(err instanceof JwtTokenExpired ? 'Expired JWT Token' : 'Authentication failed');
}
},
});

export const auth: MiddlewareHandler = async (c: AppContext, next: Next): Promise<any> => {
try {
await jwt(c, next);
} catch (e: any) {
return c.json({error: e.message && e.message.length > 0 ? e.message : 'Authentication failed'}, 401);
}
};
2 replies
HHono
Created by iEmix on 8/8/2024 in #help
Zod why error
I hack this
request: {
query: z.object({
limit: z.string().optional(),
order: z.string().optional(),
after: z.string().optional(),
before: z.string().optional(),
}) as RouteParameter,
},
request: {
query: z.object({
limit: z.string().optional(),
order: z.string().optional(),
after: z.string().optional(),
before: z.string().optional(),
}) as RouteParameter,
},
4 replies
HHono
Created by iEmix on 8/8/2024 in #help
Zod why error
code works by i recive error in phpstorm
4 replies