Skip to content

Commit

Permalink
fix auth
Browse files Browse the repository at this point in the history
  • Loading branch information
chanwit-y committed Nov 4, 2024
1 parent 721e575 commit 8eb7495
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions libs/middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ const authMiddleware: MiddlewareHandler = async (c, next) => {
if (accessToken) {
const srv = container.get<IUserService>(Instances.UserService);
const { data, error } = await srv.getUser(accessToken);
// console.log(accessToken);
console.log(data);
console.log(error);
// console.log(accessToken);
// console.log(data);
// console.log(error);
if (data.user) {
c.set("user", { ...data });
}
if (error) {
return c.json({ error: error.message }, 401);
}
} else {
return c.json({ error: "Access token not found!" }, 401);
}
await next();
};
Expand Down
6 changes: 5 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { container, Instances } from "./libs/config/container.ts";
import type { IVocabularyService } from "./libs/mod/vocabulary/service.ts";
import authRoutes from "./libs/mod/auth/routes.ts";
import vocabularyRoutes from "./libs/mod/vocabulary/routes.ts";
import authMiddleware from "./libs/middleware/auth.middleware.ts";

// const readToken = "read";
// const prvilegedToekn = "read+write";
// const privilegedMethods = ["POST", "PUT", "PATCH", "DELETE"];
const privilegedMethods = ["POST", "PUT", "PATCH", "DELETE"];

const app = new Hono();

Expand All @@ -16,6 +17,9 @@ const app = new Hono();
// return brearer(c, next);
// });


// app.on(privilegedMethods, "/api/vocabulary/*", authMiddleware);

// app.on(privilegedMethods, "/api/*", (c, next) => {
// const bearer = bearerAuth({ token: prvilegedToekn });
// return bearer(c, next);
Expand Down

0 comments on commit 8eb7495

Please sign in to comment.