@samhammer/authentication-vue
Advanced tools
| declare class AuthLogger { | ||
| private prefix; | ||
| debug(...messages: unknown[]): void; | ||
| log(...messages: unknown[]): void; | ||
| warn(...messages: unknown[]): void; | ||
| error(...messages: unknown[]): void; | ||
| } | ||
| declare const _default: AuthLogger; | ||
| export default _default; |
| class AuthLogger { | ||
| prefix = "[SAGAUTH]"; | ||
| debug(...messages) { | ||
| console.debug(this.prefix, ...messages); | ||
| } | ||
| log(...messages) { | ||
| console.log(this.prefix, ...messages); | ||
| } | ||
| warn(...messages) { | ||
| console.warn(this.prefix, ...messages); | ||
| } | ||
| error(...messages) { | ||
| console.error(this.prefix, ...messages); | ||
| } | ||
| } | ||
| export default new AuthLogger(); |
+19
-15
@@ -7,2 +7,3 @@ import Keycloak from "keycloak-js"; | ||
| import StoreProvider from "./StoreProvider"; | ||
| import AuthLogger from "./AuthLogger"; | ||
| export class AuthPlugin { | ||
@@ -107,8 +108,10 @@ authOptions; | ||
| }; | ||
| return this.initKeycloak(); | ||
| AuthLogger.log("Init keycloak"); | ||
| return await this.initKeycloak(); | ||
| } | ||
| catch (error) { | ||
| console.error("auth init failed", error); | ||
| AuthLogger.warn("Init keycloak failed", error); | ||
| await this.clearStorage(); | ||
| return false; | ||
| AuthLogger.log("Retry init keycloak without tokens"); | ||
| return await this.initKeycloak(); | ||
| } | ||
@@ -133,5 +136,3 @@ } | ||
| }); | ||
| if (authenticated) { | ||
| console.debug("authenticated keycloak"); | ||
| } | ||
| AuthLogger.debug(authenticated ? "Authenticated keycloak" : "Not authenticated keycloak"); | ||
| return authenticated; | ||
@@ -144,3 +145,3 @@ } | ||
| async login(redirectUri, idp) { | ||
| console.debug("login navigating to keycloak with returnUrl", redirectUri); | ||
| AuthLogger.debug("Login navigating to keycloak with returnUrl", redirectUri); | ||
| if (!this.pluginState || !this.pluginState?.keycloak) | ||
@@ -151,3 +152,3 @@ throw new Error("Init has to be called first"); | ||
| createLoginUrl(redirectUri, idp) { | ||
| console.debug("create loginUrl to keycloak with returnUrl", redirectUri); | ||
| AuthLogger.debug("Create loginUrl to keycloak with returnUrl", redirectUri); | ||
| if (!this.pluginState || !this.pluginState.keycloak) | ||
@@ -158,3 +159,3 @@ throw new Error("Init has to be called first"); | ||
| createLogoutUrl(redirectUri) { | ||
| console.debug("create logoutUrl to keycloak with returnUrl", redirectUri); | ||
| AuthLogger.debug("Create logoutUrl to keycloak with returnUrl", redirectUri); | ||
| if (!this.pluginState || !this.pluginState.keycloak) | ||
@@ -165,3 +166,3 @@ throw new Error("Init has to be called first"); | ||
| async logout(redirectUri) { | ||
| console.debug("logout navigating to keycloak with returnUrl", redirectUri); | ||
| AuthLogger.debug("Logout navigating to keycloak with returnUrl", redirectUri); | ||
| await this.clearStorage(); | ||
@@ -192,7 +193,7 @@ if (!this.pluginState || !this.pluginState.keycloak) | ||
| if (successful) { | ||
| console.debug("token refreshed"); | ||
| AuthLogger.debug("Token refreshed"); | ||
| } | ||
| } | ||
| catch (error) { | ||
| console.error("token refresh failed", error || "token may be empty"); | ||
| AuthLogger.error("Token refresh failed", error || "token may be empty"); | ||
| } | ||
@@ -237,4 +238,7 @@ } | ||
| guestRoles = authOptions.guestRoles || ["User"]; | ||
| console.debug("authenticated guest"); | ||
| AuthLogger.debug("Authenticated guest"); | ||
| } | ||
| else { | ||
| AuthLogger.debug("Not authenticated guest"); | ||
| } | ||
| this.pluginState = { | ||
@@ -248,3 +252,3 @@ guestKey: guestKey, | ||
| async login(authOptions) { | ||
| console.debug("login guest"); | ||
| AuthLogger.debug("Login guest"); | ||
| if (!this.pluginState) | ||
@@ -258,3 +262,3 @@ throw new Error("Init has to be called first"); | ||
| async logout() { | ||
| console.debug("logout guest"); | ||
| AuthLogger.debug("Logout guest"); | ||
| if (!this.pluginState) | ||
@@ -261,0 +265,0 @@ return; |
| import { AuthEvents, AuthEventNames } from "./AuthEvents"; | ||
| import Auth from "./index"; | ||
| import AuthLogger from "./AuthLogger"; | ||
| export class AxiosAuthInterceptor { | ||
@@ -21,7 +22,7 @@ static addAuthTokenInterceptor(axiosInstance) { | ||
| if (error.response?.status === 401) { | ||
| console.warn("axios api request requires authentication", error.config?.url, error.message); | ||
| AuthLogger.warn("Axios api request requires authentication", error.config?.url, error.message); | ||
| AuthEvents.emit(AuthEventNames.loginRequired); | ||
| } | ||
| else if (error.response?.status === 403) { | ||
| console.warn("axios api request requires permission", error.config?.url, error.message); | ||
| AuthLogger.warn("Axios api request requires permission", error.config?.url, error.message); | ||
| AuthEvents.emit(AuthEventNames.permissionDenied); | ||
@@ -28,0 +29,0 @@ } |
+1
-1
| { | ||
| "name": "@samhammer/authentication-vue", | ||
| "version": "2.4.3", | ||
| "version": "2.5.0", | ||
| "description": "Keycloak authentication for VueJS projects", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
18215
5.86%17
13.33%447
7.19%