0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-09 00:42:47 +00:00

Require user to be logged in to change name

This commit is contained in:
Trevor Buckner
2024-12-18 12:14:08 -05:00
committed by GitHub
parent 0148eafce0
commit aee5b7a8cc

View File

@@ -351,11 +351,12 @@ app.get('/user/:username', async (req, res, next)=>{
//Change author name on brews //Change author name on brews
app.put('/api/user/rename', async (req, res)=>{ app.put('/api/user/rename', async (req, res)=>{
const { username, newUsername } = req.body; const { username, newUsername } = req.body;
console.log(req.account); const ownAccount = req.account && (req.account.username == newUsername);
if(!username || !newUsername) { if(!username || !newUsername)
return res.status(400).json({ error: 'Username and newUsername are required.' }); return res.status(400).json({ error: 'Username and newUsername are required.' });
} if(!ownAccount)
return res.status(403).json({ error: 'Must be logged in to change your username' });
try { try {
const brews = await HomebrewModel.getByUser(username, true, ['authors']); const brews = await HomebrewModel.getByUser(username, true, ['authors']);
const renamePromises = brews.map(async (brew)=>{ const renamePromises = brews.map(async (brew)=>{