LifeMate — Personal, Family & Learning Companion
feat: apply profile theme defaults from family invitations
davoodmehraban89 committed
Oct 5, 2026 at 07:50 UTC
b733417377c463db94697a2804af0888cf3f4c4d
1 file changed
+17
-4
backend/src/server.js
+17
-4
@@ -118,7 +118,7 @@ app.post('/v1/auth/register', async (req, res) => {
118
[`local:${crypto.randomUUID()}`, email],
119
);
120
await client.query(
121
- 'insert into profile(user_id,display_name) values($1,$2)',
121
+ "insert into profile(user_id,display_name,theme_preference) values($1,$2,'adult_blue')",
122
[u.rows[0].id, name],
123
);
124
await client.query(
@@ -432,15 +432,22 @@ app.post('/v1/families/:familyId/invitations', auth, async (req, res) => {
432
433
const email = normalizeEmail(req.body.email);
434
const role = String(req.body.role ?? '');
435
+ const themePreference = String(req.body.themePreference ?? '');
436
const allowedRoles = ['parent_guardian', 'teen_minor', 'adult_member'];
437
+ const allowedThemes = ['girl_pink', 'boy_blue', 'adult_blue', 'custom'];
438
+ const resolvedTheme = allowedThemes.includes(themePreference)
439
+ ? themePreference
440
+ : role === 'teen_minor'
441
+ ? 'girl_pink'
442
+ : 'adult_blue';
443
if (!isEmail(email) || !allowedRoles.includes(role)) {
444
return res.status(400).json({ error: 'invalid_invitation' });
445
}
446
447
const token = randomToken();
448
const r = await pool.query(
442
- "insert into family_invitation(family_id,invited_email_normalized,intended_role,token_digest,invited_by,expires_at) values($1,$2,$3,$4,$5,now()+interval '7 days') returning id,expires_at",
443
- [req.params.familyId, email, role, sha256(token), req.identity.sub],
449
+ "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",
450
+ [req.params.familyId, email, role, resolvedTheme, sha256(token), req.identity.sub],
451
);
452
453
const baseUrl = process.env.PUBLIC_APP_URL ?? 'https://app.lifemate.invalid';
@@ -462,7 +469,7 @@ app.post('/v1/invitations/accept', auth, async (req, res) => {
469
try {
470
await client.query('begin');
471
const invitation = await client.query(
465
- `select i.id,i.family_id,i.intended_role,i.invited_email_normalized,u.email_normalized
472
+ `select i.id,i.family_id,i.intended_role,i.intended_theme,i.invited_email_normalized,u.email_normalized
473
from family_invitation i
474
join app_user u on u.id=$2
475
where i.token_digest=$1
@@ -492,6 +499,12 @@ app.post('/v1/invitations/accept', auth, async (req, res) => {
499
"update family_invitation set status='accepted',accepted_by=$2,accepted_at=now() where id=$1",
500
[row.id, req.identity.sub],
501
);
502
+ if (row.intended_theme) {
503
+ await client.query(
504
+ 'update profile set theme_preference=$2,updated_at=now() where user_id=$1',
505
+ [req.identity.sub, row.intended_theme],
506
+ );
507
+ }
508
await client.query(
509
"insert into access_audit(actor_user_id,family_id,action,target_type,target_id) values($1,$2,'invitation.accept','membership',$3)",
510
[req.identity.sub, row.family_id, String(req.identity.sub)],