@nymphjs/tilmeld 1.0.0-beta.40 → 1.0.0-beta.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Tilmeld.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  Options,
6
6
  TilmeldInterface,
7
7
  TilmeldAccessLevels,
8
+ ACProperties,
8
9
  } from '@nymphjs/nymph';
9
10
  import { URL } from 'url';
10
11
  import { Request, Response } from 'express';
@@ -70,14 +71,17 @@ export default class Tilmeld implements TilmeldInterface {
70
71
  public response: Response | null = null;
71
72
 
72
73
  /**
73
- * Skip the authenticate step of initialization.
74
+ * Used to avoid infinite loop.
74
75
  */
75
- private skipAuthenticate = false;
76
+ private alreadyLoggedOutSwitch = false;
76
77
 
77
78
  /**
78
- * Used to avoid infinite loop.
79
+ * Gatekeeper ability cache.
80
+ *
81
+ * Gatekeeper will cache the user's abilities that it calculates, so it can
82
+ * check faster if that user has been checked before.
79
83
  */
80
- private alreadyLoggedOutSwitch = false;
84
+ private gatekeeperCache: { [k: string]: true } | null = null;
81
85
 
82
86
  /**
83
87
  * Create a new instance of Tilmeld.
@@ -98,7 +102,7 @@ export default class Tilmeld implements TilmeldInterface {
98
102
  tilmeld.request = this.request;
99
103
  tilmeld.response = this.response;
100
104
  tilmeld.currentUser = this.currentUser;
101
- tilmeld.skipAuthenticate = true;
105
+ tilmeld.gatekeeperCache = this.gatekeeperCache;
102
106
 
103
107
  return tilmeld;
104
108
  }
@@ -143,15 +147,13 @@ export default class Tilmeld implements TilmeldInterface {
143
147
  user.mdate = currentUserMDate;
144
148
  user.tags = currentUserTags;
145
149
  user.$putData(currentUserData, currentUserSData);
146
- this.fillSession(user);
150
+ this.currentUser = user;
151
+ this.currentUser.$updateDataProtection();
152
+ this.currentUser.$updateGroupDataProtection();
147
153
  }
148
154
 
149
155
  // Set up access control hooks when Nymph is called.
150
156
  this.initAccessControl();
151
- if (this.request != null && !this.skipAuthenticate) {
152
- this.authenticate();
153
- }
154
- this.skipAuthenticate = false;
155
157
  }
156
158
 
157
159
  /**
@@ -163,11 +165,17 @@ export default class Tilmeld implements TilmeldInterface {
163
165
  * @param ability The ability.
164
166
  * @returns Whether the user has the given ability.
165
167
  */
166
- public gatekeeper(ability?: string): boolean {
167
- if (this.currentUser == null) {
168
+ public gatekeeper(ability?: string) {
169
+ if (this.currentUser == null || this.gatekeeperCache == null) {
168
170
  return false;
169
171
  }
170
- return this.currentUser.$gatekeeper(ability);
172
+ if (ability == null) {
173
+ return true;
174
+ }
175
+ return (
176
+ (ability in this.gatekeeperCache && !!this.gatekeeperCache[ability]) ||
177
+ !!this.currentUser.abilities?.includes('system/admin')
178
+ );
171
179
  }
172
180
 
173
181
  private initAccessControl() {
@@ -186,7 +194,9 @@ export default class Tilmeld implements TilmeldInterface {
186
194
  ) {
187
195
  if (options?.source === 'client') {
188
196
  if (
189
- !tilmeld.gatekeeper('tilmeld/admin') && // The user is not an admin.
197
+ (!tilmeld.currentUser ||
198
+ (!tilmeld.currentUser.abilities?.includes('tilmeld/admin') &&
199
+ !tilmeld.currentUser.abilities?.includes('system/admin'))) && // The user is not an admin.
190
200
  ((!tilmeld.config.enableUserSearch &&
191
201
  options.class?.factorySync() instanceof User) || // The use is searching for a user and searching is disabled.
192
202
  (!tilmeld.config.enableGroupSearch &&
@@ -237,7 +247,7 @@ export default class Tilmeld implements TilmeldInterface {
237
247
  guid: string,
238
248
  className?: string
239
249
  ) {
240
- const entity = nymph.driver.getEntitySync(
250
+ const entity = await nymph.getEntity(
241
251
  { class: nymph.getEntityClass(className ?? 'Entity') },
242
252
  { type: '&', guid: guid }
243
253
  );
@@ -269,35 +279,9 @@ export default class Tilmeld implements TilmeldInterface {
269
279
  // allowing a change to ac properties.
270
280
 
271
281
  const originalAc = entity.$getOriginalAcValues();
272
- const newAc: AccessControlData = {
273
- user: entity.user ?? undefined,
274
- group: entity.group ?? undefined,
275
- acUser: entity.acUser ?? undefined,
276
- acGroup: entity.acGroup ?? undefined,
277
- acOther: entity.acOther ?? undefined,
278
- acRead: entity.acRead ?? undefined,
279
- acWrite: entity.acWrite ?? undefined,
280
- acFull: entity.acFull ?? undefined,
281
- };
282
-
283
- const setAcProperties = (acValues: { [k: string]: any }) => {
284
- for (let name in acValues) {
285
- const value = acValues[name];
286
- if (value == null) {
287
- delete entity[name];
288
- } else {
289
- entity[name] = value;
290
- }
291
- }
292
- };
282
+ const newAc = entity.$getCurrentAcValues();
293
283
 
294
- // Restore original AC properties and check permissions.
295
- setAcProperties(originalAc);
296
-
297
- function areAcPropertiesChanged(
298
- a: AccessControlData,
299
- b: AccessControlData
300
- ) {
284
+ function areAcPropertiesChanged(a: ACProperties, b: ACProperties) {
301
285
  for (const name of ['user', 'group'] as ('user' | 'group')[]) {
302
286
  const aVal = a[name];
303
287
  const bVal = b[name];
@@ -306,7 +290,7 @@ export default class Tilmeld implements TilmeldInterface {
306
290
  } else if (aVal == null || bVal == null) {
307
291
  return true;
308
292
  }
309
- if (!aVal.$is(bVal)) {
293
+ if (aVal !== bVal) {
310
294
  return true;
311
295
  }
312
296
  }
@@ -341,12 +325,7 @@ export default class Tilmeld implements TilmeldInterface {
341
325
  if (aVal.length !== bVal.length) {
342
326
  return true;
343
327
  }
344
- if (
345
- xor(
346
- aVal.map((entity) => entity.guid),
347
- bVal.map((entity) => entity.guid)
348
- ).length
349
- ) {
328
+ if (xor(aVal, bVal).length) {
350
329
  return true;
351
330
  }
352
331
  }
@@ -355,7 +334,12 @@ export default class Tilmeld implements TilmeldInterface {
355
334
 
356
335
  if (areAcPropertiesChanged(originalAc, newAc)) {
357
336
  if (
358
- !tilmeld.checkPermissions(entity, TilmeldAccessLevels.FULL_ACCESS)
337
+ !tilmeld.checkPermissions(
338
+ entity,
339
+ TilmeldAccessLevels.FULL_ACCESS,
340
+ undefined,
341
+ originalAc
342
+ )
359
343
  ) {
360
344
  // Only allow changes to AC properties if the user has full access.
361
345
  throw new AccessControlError(
@@ -364,10 +348,10 @@ export default class Tilmeld implements TilmeldInterface {
364
348
  }
365
349
 
366
350
  if (
367
- (originalAc.user && !originalAc.user.$is(newAc.user)) ||
351
+ (originalAc.user && originalAc.user !== newAc.user) ||
368
352
  (!originalAc.user &&
369
353
  newAc.user &&
370
- !newAc.user.$is(tilmeld.currentUser))
354
+ newAc.user !== tilmeld.currentUser)
371
355
  ) {
372
356
  throw new AccessControlError(
373
357
  'No permission to assign to another user.'
@@ -376,18 +360,15 @@ export default class Tilmeld implements TilmeldInterface {
376
360
 
377
361
  if (
378
362
  newAc.group &&
379
- !newAc.group.$is(originalAc.group) &&
380
- !(
381
- newAc.group.$is(tilmeld.currentUser?.group) ||
382
- newAc.group.$inArray(tilmeld.currentUser?.groups ?? [])
383
- )
363
+ newAc.group !== originalAc.group &&
364
+ !(newAc.group =
365
+ tilmeld.currentUser?.$getGid() ||
366
+ (tilmeld.currentUser?.$getGids() ?? []).includes(newAc.group))
384
367
  ) {
385
368
  throw new AccessControlError(
386
369
  'No permission to assign to another group.'
387
370
  );
388
371
  }
389
-
390
- setAcProperties(newAc);
391
372
  }
392
373
  }
393
374
 
@@ -429,12 +410,11 @@ export default class Tilmeld implements TilmeldInterface {
429
410
  if (entity.user == null) {
430
411
  entity.user = user;
431
412
  }
432
- if (
433
- entity.group == null &&
434
- user.group != null &&
435
- user.group.guid != null
436
- ) {
437
- entity.group = user.group;
413
+ if (entity.group == null) {
414
+ const group = user.group;
415
+ if (group != null && group.guid != null) {
416
+ entity.group = group;
417
+ }
438
418
  }
439
419
  if (entity.acUser == null) {
440
420
  entity.acUser = TilmeldAccessLevels.FULL_ACCESS;
@@ -589,33 +569,23 @@ export default class Tilmeld implements TilmeldInterface {
589
569
  ];
590
570
  const groupRefs: FormattedSelector['ref'] = [];
591
571
  const acRefs: FormattedSelector['ref'] = [];
592
- if (user.group != null && user.group.guid != null) {
572
+ const gid = user.$getGid();
573
+ if (gid != null) {
593
574
  // It belongs to the user's primary group.
594
- groupRefs.push(['group', user.group.guid]);
575
+ groupRefs.push(['group', gid]);
595
576
  // User's primary group is listed in acRead, acWrite, or acFull.
596
- acRefs.push(['acRead', user.group.guid]);
597
- acRefs.push(['acWrite', user.group.guid]);
598
- acRefs.push(['acFull', user.group.guid]);
577
+ acRefs.push(['acRead', gid]);
578
+ acRefs.push(['acWrite', gid]);
579
+ acRefs.push(['acFull', gid]);
599
580
  }
600
- for (let curSecondaryGroup of user.groups ?? []) {
601
- if (curSecondaryGroup != null && curSecondaryGroup.guid != null) {
602
- // It belongs to the user's secondary group.
603
- groupRefs.push(['group', curSecondaryGroup.guid]);
604
- // User's secondary group is listed in acRead, acWrite, or acFull.
605
- acRefs.push(['acRead', curSecondaryGroup.guid]);
606
- acRefs.push(['acWrite', curSecondaryGroup.guid]);
607
- acRefs.push(['acFull', curSecondaryGroup.guid]);
608
- }
609
- }
610
- for (let curDescendantGroup of user.$getDescendantGroupsSync()) {
611
- if (curDescendantGroup != null && curDescendantGroup.guid != null) {
612
- // It belongs to the user's secondary group.
613
- groupRefs.push(['group', curDescendantGroup.guid]);
614
- // User's secondary group is listed in acRead, acWrite, or acFull.
615
- acRefs.push(['acRead', curDescendantGroup.guid]);
616
- acRefs.push(['acWrite', curDescendantGroup.guid]);
617
- acRefs.push(['acFull', curDescendantGroup.guid]);
618
- }
581
+ const gids = user.$getGids();
582
+ for (let curGid of gids ?? []) {
583
+ // It belongs to the user's secondary group.
584
+ groupRefs.push(['group', curGid]);
585
+ // User's secondary group is listed in acRead, acWrite, or acFull.
586
+ acRefs.push(['acRead', curGid]);
587
+ acRefs.push(['acWrite', curGid]);
588
+ acRefs.push(['acFull', curGid]);
619
589
  }
620
590
  // All the group refs.
621
591
  if (groupRefs.length) {
@@ -714,16 +684,17 @@ export default class Tilmeld implements TilmeldInterface {
714
684
  * @param entity The entity to check.
715
685
  * @param type The lowest level of permission to consider a pass.
716
686
  * @param user The user to check permissions for. If null, uses the current user. If false, checks for public access.
687
+ * @param acProperties The acProperties to use instead of getting them from the entity.
717
688
  * @returns Whether the current user has at least `type` permission for the entity.
718
689
  */
719
690
  public checkPermissions(
720
- entity: EntityInterface & AccessControlData,
691
+ entity: EntityInterface,
721
692
  type: TilmeldAccessLevels = TilmeldAccessLevels.READ_ACCESS,
722
- user?: (User & UserData) | false
693
+ user?: (User & UserData) | false,
694
+ acProperties?: ACProperties
723
695
  ) {
724
- // Only works for entities.
725
- if (typeof entity !== 'object' || typeof entity.$is !== 'function') {
726
- return false;
696
+ if (!acProperties) {
697
+ acProperties = entity.$getCurrentAcValues() as ACProperties;
727
698
  }
728
699
 
729
700
  let userOrNull: (User & UserData) | null = null;
@@ -748,9 +719,9 @@ export default class Tilmeld implements TilmeldInterface {
748
719
  }
749
720
 
750
721
  // Load access control, since we need it now...
751
- const acUser = entity.acUser ?? TilmeldAccessLevels.FULL_ACCESS;
752
- const acGroup = entity.acGroup ?? TilmeldAccessLevels.READ_ACCESS;
753
- const acOther = entity.acOther ?? TilmeldAccessLevels.NO_ACCESS;
722
+ const acUser = acProperties.acUser ?? TilmeldAccessLevels.FULL_ACCESS;
723
+ const acGroup = acProperties.acGroup ?? TilmeldAccessLevels.READ_ACCESS;
724
+ const acOther = acProperties.acOther ?? TilmeldAccessLevels.NO_ACCESS;
754
725
 
755
726
  if (userOrNull == null) {
756
727
  return acOther >= type;
@@ -762,45 +733,41 @@ export default class Tilmeld implements TilmeldInterface {
762
733
  }
763
734
 
764
735
  // Check if the entity is the user's group. Always readable.
736
+ const gid = userOrEmpty.$getGid();
765
737
  if (
766
- userOrEmpty.group != null &&
767
- typeof userOrEmpty.group.$is === 'function' &&
768
- userOrEmpty.group.$is(entity) &&
738
+ gid != null &&
739
+ entity.guid === gid &&
769
740
  type === TilmeldAccessLevels.READ_ACCESS
770
741
  ) {
771
742
  return true;
772
743
  }
773
744
 
774
745
  // Calculate all the groups the user belongs to.
775
- let allGroups = userOrEmpty.group == null ? [] : [userOrEmpty.group];
776
- allGroups = allGroups.concat(userOrEmpty.groups ?? []);
777
- allGroups = allGroups.concat(userOrEmpty.$getDescendantGroupsSync());
746
+ let allGids = gid == null ? [] : [gid];
747
+ allGids = allGids.concat(userOrEmpty.$getGids() ?? []);
778
748
 
779
749
  // Check access ac properties.
780
750
  const checks = [
781
751
  {
782
752
  type: TilmeldAccessLevels.FULL_ACCESS,
783
- array: [...(entity.acFull ?? [])],
753
+ array: [...(acProperties.acFull ?? [])],
784
754
  },
785
755
  {
786
756
  type: TilmeldAccessLevels.WRITE_ACCESS,
787
- array: [...(entity.acWrite ?? [])],
757
+ array: [...(acProperties.acWrite ?? [])],
788
758
  },
789
759
  {
790
760
  type: TilmeldAccessLevels.READ_ACCESS,
791
- array: [...(entity.acRead ?? [])],
761
+ array: [...(acProperties.acRead ?? [])],
792
762
  },
793
763
  ];
794
764
  for (let curCheck of checks) {
795
765
  if (type <= curCheck.type) {
796
- if (userOrEmpty.$inArray(curCheck.array)) {
766
+ if (curCheck.array.includes(userOrEmpty.guid)) {
797
767
  return true;
798
768
  }
799
- for (let curGroup of allGroups) {
800
- if (
801
- typeof curGroup.$inArray === 'function' &&
802
- curGroup.$inArray(curCheck.array)
803
- ) {
769
+ for (let curGid of allGids) {
770
+ if (curCheck.array.includes(curGid)) {
804
771
  return true;
805
772
  }
806
773
  }
@@ -808,18 +775,10 @@ export default class Tilmeld implements TilmeldInterface {
808
775
  }
809
776
 
810
777
  // Check ownership ac properties.
811
- if (
812
- entity.user != null &&
813
- typeof entity.user.$is === 'function' &&
814
- entity.user.$is(userOrNull)
815
- ) {
778
+ if (acProperties.user != null && acProperties.user === userOrNull.guid) {
816
779
  return acUser >= type;
817
780
  }
818
- if (
819
- entity.group != null &&
820
- typeof entity.group.$inArray === 'function' &&
821
- entity.group.$inArray(allGroups)
822
- ) {
781
+ if (acProperties.group != null && allGids.includes(acProperties.group)) {
823
782
  return acGroup >= type;
824
783
  }
825
784
  return acOther >= type;
@@ -849,7 +808,7 @@ export default class Tilmeld implements TilmeldInterface {
849
808
  * @param user The user to check permissions for. If null, uses the current user. If false, checks for public access.
850
809
  * @returns Whether the current user has at least `type` permission for the UID.
851
810
  */
852
- public checkClientUIDPermissions(
811
+ public async checkClientUIDPermissions(
853
812
  name: string,
854
813
  type: TilmeldAccessLevels = TilmeldAccessLevels.READ_ACCESS,
855
814
  user?: (User & UserData) | false
@@ -869,23 +828,23 @@ export default class Tilmeld implements TilmeldInterface {
869
828
  if (type === TilmeldAccessLevels.FULL_ACCESS) {
870
829
  return (
871
830
  this.config.clientSetabledUIDs.indexOf(name) !== -1 ||
872
- userOrEmpty.$gatekeeper(`uid/set/${name}`)
831
+ (await userOrEmpty.$gatekeeper(`uid/set/${name}`))
873
832
  );
874
833
  } else if (type === TilmeldAccessLevels.WRITE_ACCESS) {
875
834
  return (
876
835
  this.config.clientEnabledUIDs.indexOf(name) !== -1 ||
877
836
  this.config.clientSetabledUIDs.indexOf(name) !== -1 ||
878
- userOrEmpty.$gatekeeper(`uid/new/${name}`) ||
879
- userOrEmpty.$gatekeeper(`uid/set/${name}`)
837
+ (await userOrEmpty.$gatekeeper(`uid/new/${name}`)) ||
838
+ (await userOrEmpty.$gatekeeper(`uid/set/${name}`))
880
839
  );
881
840
  } else if (type === TilmeldAccessLevels.READ_ACCESS) {
882
841
  return (
883
842
  this.config.clientReadableUIDs.indexOf(name) !== -1 ||
884
843
  this.config.clientEnabledUIDs.indexOf(name) !== -1 ||
885
844
  this.config.clientSetabledUIDs.indexOf(name) !== -1 ||
886
- userOrEmpty.$gatekeeper(`uid/get/${name}`) ||
887
- userOrEmpty.$gatekeeper(`uid/new/${name}`) ||
888
- userOrEmpty.$gatekeeper(`uid/set/${name}`)
845
+ (await userOrEmpty.$gatekeeper(`uid/get/${name}`)) ||
846
+ (await userOrEmpty.$gatekeeper(`uid/new/${name}`)) ||
847
+ (await userOrEmpty.$gatekeeper(`uid/set/${name}`))
889
848
  );
890
849
  }
891
850
 
@@ -897,20 +856,13 @@ export default class Tilmeld implements TilmeldInterface {
897
856
  *
898
857
  * @param user The user.
899
858
  */
900
- public fillSession(user: User & UserData) {
901
- // Read groups right now, since gatekeeper needs them, so
902
- // $udpateDataProtection will fail to read them (since it runs gatekeeper).
903
- const _group = user.group;
904
- const _groups = user.groups;
859
+ public async fillSession(user: User & UserData) {
905
860
  this.currentUser = user;
861
+ this.gatekeeperCache = await user.$getGatekeeperCache();
862
+
906
863
  // Now update the data protection on the user and all the groups.
907
864
  this.currentUser.$updateDataProtection();
908
- if (this.currentUser.group != null) {
909
- this.currentUser.group.$updateDataProtection();
910
- }
911
- for (let group of this.currentUser.groups ?? []) {
912
- group.$updateDataProtection();
913
- }
865
+ this.currentUser.$updateGroupDataProtection();
914
866
  }
915
867
 
916
868
  /**
@@ -919,14 +871,10 @@ export default class Tilmeld implements TilmeldInterface {
919
871
  public clearSession() {
920
872
  const user = this.currentUser;
921
873
  this.currentUser = null;
874
+ this.gatekeeperCache = null;
922
875
  if (user) {
923
876
  user.$updateDataProtection();
924
- if (user.group != null) {
925
- user.group.$updateDataProtection();
926
- }
927
- for (let group of user.groups ?? []) {
928
- group.$updateDataProtection();
929
- }
877
+ user.$updateGroupDataProtection();
930
878
  }
931
879
  }
932
880
 
@@ -973,7 +921,7 @@ export default class Tilmeld implements TilmeldInterface {
973
921
  * @param skipXsrfToken Skip the XSRF token check.
974
922
  * @returns True if a user was authenticated, false on any failure.
975
923
  */
976
- public authenticate(skipXsrfToken = false) {
924
+ public async authenticate(skipXsrfToken = false) {
977
925
  if (this.request == null) {
978
926
  return false;
979
927
  }
@@ -985,7 +933,7 @@ export default class Tilmeld implements TilmeldInterface {
985
933
  ) {
986
934
  // The user has already been authenticated through some other means.
987
935
  const user = this.response.locals.user;
988
- this.fillSession(user);
936
+ await this.fillSession(user);
989
937
  return true;
990
938
  }
991
939
 
@@ -1039,7 +987,7 @@ export default class Tilmeld implements TilmeldInterface {
1039
987
  }
1040
988
 
1041
989
  if (authExtract == null) {
1042
- this.logout();
990
+ await this.logout();
1043
991
  return false;
1044
992
  }
1045
993
  const { guid, issued, expire } = authExtract;
@@ -1048,7 +996,7 @@ export default class Tilmeld implements TilmeldInterface {
1048
996
  expire: null,
1049
997
  };
1050
998
 
1051
- const user = this.User.factorySync(guid);
999
+ const user = await this.User.factory(guid);
1052
1000
  if (
1053
1001
  user.guid == null ||
1054
1002
  !user.enabled ||
@@ -1056,17 +1004,17 @@ export default class Tilmeld implements TilmeldInterface {
1056
1004
  issued.getTime() > Date.now() ||
1057
1005
  (user.revokeTokenDate != null && issued.getTime() <= user.revokeTokenDate)
1058
1006
  ) {
1059
- this.logout();
1007
+ await this.logout();
1060
1008
  return false;
1061
1009
  }
1062
1010
 
1063
1011
  if (switchGuid && switchExpire && switchExpire.getTime() > Date.now()) {
1064
1012
  // Load the switch user.
1065
- const switchUser = this.User.factorySync(switchGuid);
1013
+ const switchUser = await this.User.factory(switchGuid);
1066
1014
  if (switchUser.guid == null) {
1067
- this.logoutSwitch();
1015
+ await this.logoutSwitch();
1068
1016
  } else {
1069
- this.fillSession(switchUser);
1017
+ await this.fillSession(switchUser);
1070
1018
 
1071
1019
  if (this.response) {
1072
1020
  this.response.locals.user = switchUser;
@@ -1079,9 +1027,9 @@ export default class Tilmeld implements TilmeldInterface {
1079
1027
  if (expire.getTime() < Date.now() + this.config.jwtRenew * 1000) {
1080
1028
  // If the user is less than renew time from needing a new token, give them
1081
1029
  // a new one.
1082
- this.login(user, fromAuthHeader);
1030
+ await this.login(user, fromAuthHeader);
1083
1031
  } else {
1084
- this.fillSession(user);
1032
+ await this.fillSession(user);
1085
1033
  }
1086
1034
 
1087
1035
  if (this.response) {
@@ -1099,7 +1047,7 @@ export default class Tilmeld implements TilmeldInterface {
1099
1047
  * @param sendCookie Send the auth token as a cookie.
1100
1048
  * @returns True on success, false on failure.
1101
1049
  */
1102
- public login(
1050
+ public async login(
1103
1051
  user: User & UserData,
1104
1052
  sendAuthHeader: boolean,
1105
1053
  sendCookie = true
@@ -1129,7 +1077,7 @@ export default class Tilmeld implements TilmeldInterface {
1129
1077
  this.response.locals.user = user;
1130
1078
  }
1131
1079
 
1132
- this.fillSession(user);
1080
+ await this.fillSession(user);
1133
1081
  return true;
1134
1082
  }
1135
1083
  return false;
@@ -1145,7 +1093,7 @@ export default class Tilmeld implements TilmeldInterface {
1145
1093
  * @param sendCookie Send the auth token as a cookie.
1146
1094
  * @returns True on success, false on failure.
1147
1095
  */
1148
- public loginSwitch(
1096
+ public async loginSwitch(
1149
1097
  user: User & UserData,
1150
1098
  sendAuthHeader: boolean,
1151
1099
  sendCookie = true
@@ -1175,7 +1123,7 @@ export default class Tilmeld implements TilmeldInterface {
1175
1123
  this.response.locals.user = user;
1176
1124
  }
1177
1125
 
1178
- this.fillSession(user);
1126
+ await this.fillSession(user);
1179
1127
  return true;
1180
1128
  }
1181
1129
  return false;
@@ -1186,13 +1134,13 @@ export default class Tilmeld implements TilmeldInterface {
1186
1134
  *
1187
1135
  * @param clearCookie Clear the auth cookie. (Also send a header.)
1188
1136
  */
1189
- public logout(clearCookie = true) {
1137
+ public async logout(clearCookie = true) {
1190
1138
  if (this.request && !this.alreadyLoggedOutSwitch) {
1191
1139
  const cookies = this.request.cookies ?? {};
1192
1140
 
1193
1141
  if ('TILMELDSWITCH' in cookies) {
1194
1142
  this.alreadyLoggedOutSwitch = true;
1195
- return this.logoutSwitch(clearCookie);
1143
+ return await this.logoutSwitch(clearCookie);
1196
1144
  }
1197
1145
  }
1198
1146
 
@@ -1214,7 +1162,7 @@ export default class Tilmeld implements TilmeldInterface {
1214
1162
  *
1215
1163
  * @param clearCookie Clear the auth cookie. (Also send a header.)
1216
1164
  */
1217
- public logoutSwitch(clearCookie = true) {
1165
+ public async logoutSwitch(clearCookie = true) {
1218
1166
  this.clearSession();
1219
1167
  if (this.response) {
1220
1168
  if (clearCookie && !this.response.headersSent) {
@@ -1226,7 +1174,7 @@ export default class Tilmeld implements TilmeldInterface {
1226
1174
  }
1227
1175
  this.response.locals.user = null;
1228
1176
 
1229
- this.authenticate();
1177
+ await this.authenticate();
1230
1178
  }
1231
1179
  }
1232
1180