fix(together): JWT なし username 認証を復元(Posimai アカウント不要メンバー対応)

This commit is contained in:
posimai 2026-04-22 09:37:11 +09:00
parent 45893eb453
commit 4390748534
1 changed files with 24 additions and 15 deletions

View File

@ -807,10 +807,7 @@ async function togetherEnsureMember(pool, res, groupId, username, jwtUserId) {
return false;
}
try {
if (!jwtUserId) {
res.status(401).json({ error: '認証が必要です' });
return false;
}
if (jwtUserId) {
const strict = await pool.query(
`SELECT 1 FROM together_members m
WHERE m.group_id = $1 AND (
@ -825,6 +822,18 @@ async function togetherEnsureMember(pool, res, groupId, username, jwtUserId) {
if (strict.rows.length > 0) return true;
res.status(403).json({ error: 'グループのメンバーではありません' });
return false;
}
// JWT なし: username のみで照合Together は Posimai アカウント不要のため継続許容)
const primaryUsername = usernames[0];
const legacyOnly = await pool.query(
'SELECT 1 FROM together_members WHERE group_id=$1 AND username=$2',
[gidNum, primaryUsername]
);
if (legacyOnly.rows.length === 0) {
res.status(403).json({ error: 'グループのメンバーではありません' });
return false;
}
return true;
} catch (e) {
console.error('[Together] togetherEnsureMember', e.message);
res.status(500).json({ error: 'Internal server error' });