feat: Add fresh fucking entities

This commit is contained in:
Wanjohi
2025-10-26 04:39:36 +03:00
parent 6f6616ce6c
commit 16a1c8c145
14 changed files with 245 additions and 166 deletions

View File

@@ -2,6 +2,7 @@ import { subjects } from "@/subjects";
import { MiddlewareHandler } from "hono";
import { Actor } from "@nestri/core/actor";
import { Api } from "@nestri/core/api/index";
import { Member } from "@nestri/core/member/index";
import { createClient } from "@openauthjs/openauth/client";
import { VisibleError, ErrorCodes } from "@nestri/core/error";
@@ -52,13 +53,36 @@ export const auth: MiddlewareHandler = async (c, next) => {
"Invalid bearer token",
);
if (result.subject.type === "team") {
const memberID =
c.req.header("x-nestri-member") || c.req.query("memberID");
if (!memberID) {
return Actor.provide(
"team",
{
email: result.subject.properties.email,
teamID: result.subject.properties.teamID,
},
next,
);
}
return Actor.provide(
"team",
"system",
{
email: result.subject.properties.email,
teamID: result.subject.properties.teamID,
},
next,
async () => {
const member = await Member.fromID(email);
if (!member || member.timeDeleted) {
c.status(401);
return c.text("Unauthorized: User not found");
}
return Actor.provide(
"member",
{ memberID: member.id, teamID: member.workspaceID },
next,
);
},
);
}
}