Allow members to connect and manage their Facebook pages

This commit is contained in:
Loma Bot Ops
2026-11-24 09:43:34 +07:00
parent 7f1a9face1
commit b14a9286cd
9 changed files with 90 additions and 40 deletions
+6 -3
View File
@@ -49,11 +49,14 @@ export function forgetPageToken(pageId: string) {
}
/** Every token source for listing pages: system user (env, optional) + each Facebook login connection. */
export async function getPageSources(): Promise<PageSource[]> {
export async function getPageSources(user: { id: string; globalRole: string }): Promise<PageSource[]> {
const sources: PageSource[] = [];
const sys = systemUserSource();
const sys = user.globalRole === "SUPERADMIN" ? systemUserSource() : null;
if (sys) sources.push(sys);
const connections = await prisma.metaConnection.findMany({ orderBy: { createdAt: "asc" } });
const connections = await prisma.metaConnection.findMany({
where: user.globalRole === "MEMBER" ? { connectedById: user.id } : undefined,
orderBy: { createdAt: "asc" },
});
for (const c of connections) {
sources.push({ connectionId: c.id, label: c.name, token: decryptToken(c.tokenCipher) });
}