Update artifacts/api-server/src/routes/admin/index.ts
Browse files
artifacts/api-server/src/routes/admin/index.ts
CHANGED
|
@@ -191,6 +191,10 @@ router.delete("/users/:id", async (req: Request, res: Response) => {
|
|
| 191 |
try {
|
| 192 |
await db.delete(subscriptionsTable).where(eq(subscriptionsTable.userId, targetId));
|
| 193 |
await db.delete(usersTable).where(eq(usersTable.id, targetId));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
res.json({ success: true, message: "تم حذف المستخدم" });
|
| 195 |
} catch (err: any) {
|
| 196 |
res.status(500).json({ error: err.message });
|
|
@@ -239,6 +243,7 @@ router.delete("/blocked-emails/:email", async (req: Request, res: Response) => {
|
|
| 239 |
}
|
| 240 |
});
|
| 241 |
|
|
|
|
| 242 |
router.post("/ban/:userId", async (req: Request, res: Response) => {
|
| 243 |
const owner = await requireOwner(req, res);
|
| 244 |
if (!owner) return;
|
|
@@ -248,18 +253,31 @@ router.post("/ban/:userId", async (req: Request, res: Response) => {
|
|
| 248 |
.insert(usersTable)
|
| 249 |
.values({ id: userId, isBanned: true, bannedAt: new Date() })
|
| 250 |
.onConflictDoUpdate({ target: usersTable.id, set: { isBanned: true, bannedAt: new Date() } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
res.json({ success: true });
|
| 252 |
} catch (err: any) {
|
| 253 |
res.status(500).json({ error: err.message });
|
| 254 |
}
|
| 255 |
});
|
| 256 |
|
|
|
|
| 257 |
router.post("/unban/:userId", async (req: Request, res: Response) => {
|
| 258 |
const owner = await requireOwner(req, res);
|
| 259 |
if (!owner) return;
|
| 260 |
const { userId } = req.params;
|
| 261 |
try {
|
| 262 |
await db.update(usersTable).set({ isBanned: false, bannedAt: null }).where(eq(usersTable.id, userId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
res.json({ success: true });
|
| 264 |
} catch (err: any) {
|
| 265 |
res.status(500).json({ error: err.message });
|
|
|
|
| 191 |
try {
|
| 192 |
await db.delete(subscriptionsTable).where(eq(subscriptionsTable.userId, targetId));
|
| 193 |
await db.delete(usersTable).where(eq(usersTable.id, targetId));
|
| 194 |
+
|
| 195 |
+
// 🆕 حذف من Supabase Auth
|
| 196 |
+
await supabase.auth.admin.deleteUser(targetId);
|
| 197 |
+
|
| 198 |
res.json({ success: true, message: "تم حذف المستخدم" });
|
| 199 |
} catch (err: any) {
|
| 200 |
res.status(500).json({ error: err.message });
|
|
|
|
| 243 |
}
|
| 244 |
});
|
| 245 |
|
| 246 |
+
// ✅ حظر مستخدم - مع Supabase Auth
|
| 247 |
router.post("/ban/:userId", async (req: Request, res: Response) => {
|
| 248 |
const owner = await requireOwner(req, res);
|
| 249 |
if (!owner) return;
|
|
|
|
| 253 |
.insert(usersTable)
|
| 254 |
.values({ id: userId, isBanned: true, bannedAt: new Date() })
|
| 255 |
.onConflictDoUpdate({ target: usersTable.id, set: { isBanned: true, bannedAt: new Date() } });
|
| 256 |
+
|
| 257 |
+
// 🆕 حظر المستخدم في Supabase Auth
|
| 258 |
+
await supabase.auth.admin.updateUserById(userId, {
|
| 259 |
+
ban_duration: "876000h" // 100 سنة
|
| 260 |
+
});
|
| 261 |
+
|
| 262 |
res.json({ success: true });
|
| 263 |
} catch (err: any) {
|
| 264 |
res.status(500).json({ error: err.message });
|
| 265 |
}
|
| 266 |
});
|
| 267 |
|
| 268 |
+
// ✅ رفع الحظر - مع Supabase Auth
|
| 269 |
router.post("/unban/:userId", async (req: Request, res: Response) => {
|
| 270 |
const owner = await requireOwner(req, res);
|
| 271 |
if (!owner) return;
|
| 272 |
const { userId } = req.params;
|
| 273 |
try {
|
| 274 |
await db.update(usersTable).set({ isBanned: false, bannedAt: null }).where(eq(usersTable.id, userId));
|
| 275 |
+
|
| 276 |
+
// 🆕 رفع الحظر من Supabase Auth
|
| 277 |
+
await supabase.auth.admin.updateUserById(userId, {
|
| 278 |
+
ban_duration: "none"
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
res.json({ success: true });
|
| 282 |
} catch (err: any) {
|
| 283 |
res.status(500).json({ error: err.message });
|