@samhammer/authentication-vue 2.0.0 → 2.0.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.
@@ -3,7 +3,7 @@ export declare class AuthPlugin {
3
3
  private authOptions;
4
4
  private keycloak;
5
5
  private guest;
6
- hasRole(roleName: string, apiClientId?: string): boolean;
6
+ hasRole(roleName?: string, apiClientId?: string): boolean;
7
7
  get authenticated(): boolean;
8
8
  get isGuest(): boolean;
9
9
  getToken(): Promise<string>;
package/lib/AuthPlugin.js CHANGED
@@ -24,9 +24,15 @@ export class AuthPlugin {
24
24
  return this.guest.authenticated ? this.guest.getGuestId() : this.keycloak.getToken();
25
25
  }
26
26
  initOnce = once(async (authOptions) => {
27
+ console.log("Init once for auth plugin");
27
28
  this.authOptions = authOptions;
28
- const authenticated = this.guest.init(this.authOptions) || (await this.keycloak.init(this.authOptions));
29
- if (authenticated) {
29
+ const guestAuthenticated = this.guest.init(this.authOptions);
30
+ const keyCloakAuthenticated = await this.keycloak.init(this.authOptions);
31
+ console.log("Check authenticated - " + guestAuthenticated);
32
+ if (guestAuthenticated) {
33
+ AuthEvents.emit(AuthEventNames.isGuestAuthenticated);
34
+ }
35
+ if (keyCloakAuthenticated) {
30
36
  AuthEvents.emit(AuthEventNames.isAlreadyAuthenticated);
31
37
  }
32
38
  });
@@ -201,13 +207,14 @@ class GuestPlugin {
201
207
  return this.pluginState?.guestId ?? "";
202
208
  }
203
209
  init(authOptions) {
210
+ console.log("Init Guest for:" + authOptions.guestClientId);
204
211
  if (!authOptions.guestClientId) {
205
212
  return false;
206
213
  }
207
214
  const guestKey = `${authOptions.guestClientId}-guestId`;
208
215
  const guestId = LocalStorageUtils.getItem(guestKey);
209
216
  let guestRoles = [];
210
- if (this.authenticated) {
217
+ if (guestId) {
211
218
  guestRoles = authOptions.guestRoles || ["User"];
212
219
  console.debug("authenticated guest");
213
220
  }
@@ -216,6 +223,7 @@ class GuestPlugin {
216
223
  guestId: guestId,
217
224
  guestRoles: guestRoles
218
225
  };
226
+ console.log("Return authen:" + this.authenticated);
219
227
  return this.authenticated;
220
228
  }
221
229
  login(authOptions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samhammer/authentication-vue",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Keycloak authentication for VueJS projects",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "typescript": "^4.7.4"
39
39
  },
40
40
  "dependencies": {
41
- "axios": "1.3.4",
41
+ "axios": "^1.3.4",
42
42
  "emittery": "^1.0.1",
43
43
  "keycloak-js": "^20.0.3",
44
44
  "lodash": "^4.17.21",