LifeMate — Personal, Family & Learning Companion
fix: restrict invitations to admins and block active-member role changes
davoodmehraban89 committed
Oct 5, 2026 at 09:14 UTC
9c8a813d4673f9f320d804c91a347a14a51d26db
1 file changed
+13
-1
backend/src/server.js
+13
-1
@@ -467,7 +467,6 @@ app.get('/v1/families/:familyId/members', auth, async (req, res) => {
467
468
app.post('/v1/families/:familyId/invitations', auth, async (req, res) => {
469
const allowed = await familyAccess(req.params.familyId, req.identity.sub, {
470
- roles: ['parent_guardian'],
470
admin: true,
471
});
472
if (!allowed) return res.status(403).json({ error: 'forbidden' });
@@ -486,6 +485,19 @@ app.post('/v1/families/:familyId/invitations', auth, async (req, res) => {
485
return res.status(400).json({ error: 'invalid_invitation' });
486
}
487
488
+ const activeMember = await pool.query(
489
+ `select 1
490
+ from family_membership m
491
+ join app_user u on u.id=m.user_id
492
+ where m.family_id=$1
493
+ and m.ended_at is null
494
+ and u.email_normalized=$2`,
495
+ [req.params.familyId, email],
496
+ );
497
+ if (activeMember.rowCount) {
498
+ return res.status(409).json({ error: 'member_already_active' });
499
+ }
500
+
501
const token = randomToken();
502
const r = await pool.query(
503
"insert into family_invitation(family_id,invited_email_normalized,intended_role,intended_theme,token_digest,invited_by,expires_at) values($1,$2,$3,$4,$5,$6,now()+interval '7 days') returning id,expires_at",