HonoH
Hono2y ago
MarvinKR

status 200 with empty JSON

I am not logged in when doing the api call from my vs code but it's not returning unauthorized 401 but a 200 with an empty json?
// Fetch all workflows
  .get("/", clerkMiddleware(), async (c) => {
    const auth = getAuth(c);

    if (!auth?.userId) {
      return c.json({ error: "Unauthorized" }, 401);
    }

    // Fetch the user details to get the companyId
    const [user] = await db
      .select({
        companyId: users.companyId,
      })
      .from(users)
      .where(eq(users.id, auth.userId));

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

    if (!user?.companyId) {
      return c.json({ error: "User is not affiliated with a company" }, 401);
    }

    const data = await db
      .select()
      .from(workflows)
      .where(eq(workflows.companyId, user.companyId));

    return c.json({ data });
  })
Screenshot_2024-06-21_at_00.52.56.png
Was this page helpful?