@tblabs/storage 5.2.0 → 5.2.2

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.
@@ -23,8 +23,9 @@ export declare class OnlineStorage {
23
23
  OnUserChange(handler: (user: IStorageUser) => void): this;
24
24
  Register(id: string, role: string, name: string, password: string, privileges: IStorageUserPrivileges, icon?: string, tags?: string[]): Promise<IStorageUser>;
25
25
  Logout(): this;
26
+ private CallOnUserChanged;
26
27
  get IsAuthorized(): boolean;
27
- SetUser(sender: ISender): this;
28
+ SetUser(user: IStorageUser): this;
28
29
  EnableLog(): this;
29
30
  DisableLog(): this;
30
31
  Log(...message: any[]): void;
package/OnlineStorage.js CHANGED
@@ -29,6 +29,7 @@ export class OnlineStorage {
29
29
  if (user) {
30
30
  this.user = JSON.parse(user);
31
31
  this.SetUser(this.user || this.ANONYMOUS_USER);
32
+ this.CallOnUserChanged();
32
33
  }
33
34
  }
34
35
  }
@@ -40,10 +41,10 @@ export class OnlineStorage {
40
41
  if (!result.IsSuccess) {
41
42
  throw new Error(`Could not login: ${result.ErrorMessage}`);
42
43
  }
43
- this.user = result.Result;
44
- this.SetUser(this.user || this.ANONYMOUS_USER);
44
+ this.user = result.Result || this.ANONYMOUS_USER;
45
+ this.SetUser(this.user);
45
46
  this.SaveUserInLocalStorage();
46
- this.onUserChange.forEach(handler => handler(this.user));
47
+ this.CallOnUserChanged();
47
48
  return this.user;
48
49
  }
49
50
  SaveUserInLocalStorage() {
@@ -65,14 +66,19 @@ export class OnlineStorage {
65
66
  }
66
67
  Logout() {
67
68
  this.SetUser(this.ANONYMOUS_USER);
68
- this.onUserChange.forEach(handler => handler(this.ANONYMOUS_USER));
69
+ this.SaveUserInLocalStorage();
70
+ this.CallOnUserChanged();
69
71
  return this;
70
72
  }
73
+ CallOnUserChanged() {
74
+ this.onUserChange.forEach(handler => handler(this.user));
75
+ }
71
76
  get IsAuthorized() {
72
77
  return this.user.Id !== this.ANONYMOUS_USER.Id;
73
78
  }
74
- SetUser(sender) {
75
- this._bus.SetSender(sender);
79
+ SetUser(user) {
80
+ this.user = user;
81
+ this._bus.SetSender({ Id: user.Id });
76
82
  return this;
77
83
  }
78
84
  EnableLog() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tblabs/storage",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "online storage module with auth",
5
5
  "license": "beerware",
6
6
  "main": "index.js",
Binary file
Binary file