refactor(server): corrected the middleware to be in the correct spot to work as intended
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {verify} from "hono/jwt";
|
||||
import {log} from "../../logger/logger.js";
|
||||
import {authMiddleware} from "../middleware/authMiddleware.js";
|
||||
|
||||
const session = new OpenAPIHono();
|
||||
const tags = ["Auth"];
|
||||
const JWT_SECRET = process.env.JWT_SECRET!;
|
||||
|
||||
const UserSchema = z.object({
|
||||
username: z
|
||||
@@ -21,11 +21,12 @@ const UserSchema = z.object({
|
||||
|
||||
session.openapi(
|
||||
createRoute({
|
||||
tags,
|
||||
tags: ["Auth"],
|
||||
summary: "Checks a user session based on there token",
|
||||
description: "Can post there via Authentiaction header or cookies",
|
||||
method: "get",
|
||||
path: "/",
|
||||
middleware: authMiddleware,
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
@@ -79,8 +80,10 @@ session.openapi(
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
return c.json({data: {token: token, user: payload.user}}, 200);
|
||||
} catch (error) {}
|
||||
return c.json({data: {token: "tsfds"}}, 200);
|
||||
} catch (error) {
|
||||
log.error(error, "Failed session check, user must be logged out");
|
||||
return c.json({message: "Unauthorized"}, 401);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user