fix: logged-in users can now comment without entering personal info
- Fix user data extraction in rooms page (was looking for j.user instead of direct fields)
- Add email to /api/auth/me response for logged-in user display
- User object now properly populated with id, username, role, first_name, last_name, email, comments_disabled
- Comments section now correctly shows 'Posting as {name}' for logged-in users
- Reservations and messages already use user info when logged in, only require guest info for guests
This commit is contained in:
@@ -8,7 +8,7 @@ export async function GET() {
|
|||||||
return NextResponse.json({ authenticated: false }, { status: 401 });
|
return NextResponse.json({ authenticated: false }, { status: 401 });
|
||||||
}
|
}
|
||||||
const { rows } = await db.query(
|
const { rows } = await db.query(
|
||||||
'SELECT id, username, role, first_name, last_name, comments_disabled FROM users WHERE id = $1',
|
'SELECT id, username, role, first_name, last_name, email, comments_disabled FROM users WHERE id = $1',
|
||||||
[session.id]
|
[session.id]
|
||||||
);
|
);
|
||||||
const user = rows[0] || {};
|
const user = rows[0] || {};
|
||||||
@@ -19,6 +19,7 @@ export async function GET() {
|
|||||||
id: session.id,
|
id: session.id,
|
||||||
first_name: user.first_name || null,
|
first_name: user.first_name || null,
|
||||||
last_name: user.last_name || null,
|
last_name: user.last_name || null,
|
||||||
|
email: user.email || null,
|
||||||
comments_disabled: user.comments_disabled === true,
|
comments_disabled: user.comments_disabled === true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -87,7 +87,21 @@ export default function RoomsPage() {
|
|||||||
|
|
||||||
fetch('/api/auth/me', { credentials: 'same-origin' })
|
fetch('/api/auth/me', { credentials: 'same-origin' })
|
||||||
.then((r) => r.json())
|
.then((r) => r.json())
|
||||||
.then((j) => setUser(j.user || null))
|
.then((j) => {
|
||||||
|
if (j.authenticated) {
|
||||||
|
setUser({
|
||||||
|
id: j.id,
|
||||||
|
username: j.username,
|
||||||
|
role: j.role,
|
||||||
|
first_name: j.first_name,
|
||||||
|
last_name: j.last_name,
|
||||||
|
email: j.email,
|
||||||
|
comments_disabled: j.comments_disabled,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setUser(null);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user