added afterLogout trigger (#6217)

* added afterLogout trigger

* added verification of session object in tests

* removed obsolete code

* removed unsued code

* improved tests to verify user ID
This commit is contained in:
Manuel Trezza
2019-11-16 04:52:57 +01:00
committed by Diamond Lewis
parent 5cfaaf059a
commit 5ed0885440
5 changed files with 114 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import { logger } from './logger';
export const Types = {
beforeLogin: 'beforeLogin',
afterLogout: 'afterLogout',
beforeSave: 'beforeSave',
afterSave: 'afterSave',
beforeDelete: 'beforeDelete',
@@ -32,10 +33,6 @@ const baseStore = function() {
};
function validateClassNameForTriggers(className, type) {
const restrictedClassNames = ['_Session'];
if (restrictedClassNames.indexOf(className) != -1) {
throw `Triggers are not supported for ${className} class.`;
}
if (type == Types.beforeSave && className === '_PushStatus') {
// _PushStatus uses undocumented nested key increment ops
// allowing beforeSave would mess up the objects big time
@@ -47,6 +44,16 @@ function validateClassNameForTriggers(className, type) {
// than this anti-pattern of throwing strings
throw 'Only the _User class is allowed for the beforeLogin trigger';
}
if (type === Types.afterLogout && className !== '_Session') {
// TODO: check if upstream code will handle `Error` instance rather
// than this anti-pattern of throwing strings
throw 'Only the _Session class is allowed for the afterLogout trigger.';
}
if (className === '_Session' && type !== Types.afterLogout) {
// TODO: check if upstream code will handle `Error` instance rather
// than this anti-pattern of throwing strings
throw 'Only the afterLogout trigger is allowed for the _Session class.';
}
return className;
}