mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-07 14:17:51 +02:00
fix: make sure that the user data are uptodate
This commit is contained in:
@@ -119,8 +119,7 @@ export function handleError(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getUser(req: express.Request) {
|
export async function getUser(req: express.Request) {
|
||||||
const user = (req.user as any).user;
|
function notConnected() {
|
||||||
if (!user) {
|
|
||||||
req.logout((error) => {
|
req.logout((error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`[ERROR] Error while logging out: ${error}`);
|
console.error(`[ERROR] Error while logging out: ${error}`);
|
||||||
@@ -130,7 +129,13 @@ export async function getUser(req: express.Request) {
|
|||||||
httpStatus: 401,
|
httpStatus: 401,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const model = new UserModel(user);
|
const user = (req.user as any).user;
|
||||||
model.isNew = false;
|
if (!user) {
|
||||||
|
return notConnected();
|
||||||
|
}
|
||||||
|
const model = await UserModel.findById(user.id);
|
||||||
|
if (!model) {
|
||||||
|
return notConnected();
|
||||||
|
}
|
||||||
return new User(model);
|
return new User(model);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user