Fixed heart icon in other user's stashes. Syncing stashes to session on creation and removal.

This commit is contained in:
2024-04-02 02:50:24 +02:00
parent eb423b4886
commit 5f2b696b23
4 changed files with 61 additions and 19 deletions

View File

@@ -2,6 +2,7 @@
import IPCIDR from 'ip-cidr';
import { login, signup } from '../auth.js';
import { fetchUser } from '../users.js';
function getIp(req) {
const ip = req.headers['x-forwarded-for']?.split(',')[0] || req.connection.remoteAddress; // See src/ws
@@ -35,6 +36,15 @@ export async function setUserApi(req, res, next) {
next();
}
export async function updateSessionUser(req) {
const user = await fetchUser(req.session.user.id, {}, req.session.user);
req.session.user = user;
req.user = user;
req.user.ip = req.userIp;
}
export async function loginApi(req, res) {
const user = await login(req.body, req.userIp);

View File

@@ -10,20 +10,27 @@ import {
updateStash,
} from '../stashes.js';
import { updateSessionUser } from './auth.js';
export async function createStashApi(req, res) {
const stash = await createStash(req.body, req.session.user);
await updateSessionUser(req);
res.send(stash);
}
export async function updateStashApi(req, res) {
const stash = await updateStash(Number(req.params.stashId), req.body, req.session.user);
await updateSessionUser(req);
res.send(stash);
}
export async function removeStashApi(req, res) {
await removeStash(Number(req.params.stashId), req.session.user);
await updateSessionUser(req);
res.status(204).send();
}