1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Server: Clear cookie when account has been deleted to allow viewing login page again

This commit is contained in:
Laurent Cozic 2021-09-21 10:49:41 +01:00
parent 63e88c05d9
commit 061761f224

View File

@ -1,11 +1,15 @@
import { AppContext, KoaNext } from '../utils/types';
import { contextSessionId } from '../utils/requestUtils';
import { ErrorForbidden } from '../utils/errors';
import { cookieSet } from '../utils/cookies';
export default async function(ctx: AppContext, next: KoaNext): Promise<void> {
const sessionId = contextSessionId(ctx, false);
const owner = sessionId ? await ctx.joplin.models.session().sessionUser(sessionId) : null;
if (owner && !owner.enabled) throw new ErrorForbidden('This user account is disabled. Please contact support.');
if (owner && !owner.enabled) {
cookieSet(ctx, 'sessionId', ''); // Clear cookie, otherwise the user cannot login at all anymore
throw new ErrorForbidden('This user account is disabled. Please contact support.');
}
ctx.joplin.owner = owner;
return next();
}