vue-clerk
vue-clerk copied to clipboard
use of useAuth from #clerk in middleware
Hey, I basically want to protect most of my api with clerk, also dont really need access to the userObject so i just wanted to do the auth check in middleware.
However when doing so getAuth()
returns undefined
. Any idea as how to solve this?
// server/middleware/auth.ts
import { getAuth } from "#clerk";
// import { clerkClient, getAuth } from "#clerk";
export default defineEventHandler(async (event) => {
if (event.node.req.url?.startsWith("/api")) {
const publicRoutes = ["/api/public", "/api/another-public-route"];
if (publicRoutes.includes(event.node.req.url || "")) {
return;
}
console.log("getAuth", getAuth(event)); // returns `undefined`
// const { userId } = getAuth(event);
// if (!userId) {
// throw createError({
// statusCode: 401,
// });
// }
// event.context.userId = userId;
}
});