mesauth-angular 0.1.5 → 0.1.6

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/README.md CHANGED
@@ -34,7 +34,36 @@ Angular helper library to connect to a backend API and SignalR hub to surface th
34
34
  };
35
35
  ```
36
36
 
37
- 3. Initialize in your app (e.g. `AppComponent` constructor or `AppModule` bootstrap):
37
+ 3. (Optional) Provide the HTTP interceptor to handle 403 errors:
38
+ - The interceptor redirects to `${userBaseUrl}/403?returnUrl=encodedCurrentUrl` using `window.location.href` for external URLs (since `userBaseUrl` may be outside the client app).
39
+ - **For module-based apps**: Add `MesAuthInterceptor` to providers in `AppModule`.
40
+ ```ts
41
+ import { HTTP_INTERCEPTORS } from '@angular/common/http';
42
+ import { MesAuthInterceptor } from 'mesauth-angular';
43
+
44
+ @NgModule({
45
+ // ... other module config ...
46
+ providers: [
47
+ // ... other providers ...
48
+ { provide: HTTP_INTERCEPTORS, useClass: MesAuthInterceptor, multi: true }
49
+ ]
50
+ })
51
+ export class AppModule { }
52
+ ```
53
+ - **For standalone apps**: Add `MesAuthInterceptor` to providers in `app.config.ts`.
54
+ ```ts
55
+ import { HTTP_INTERCEPTORS } from '@angular/common/http';
56
+ import { MesAuthInterceptor } from 'mesauth-angular';
57
+
58
+ export const appConfig: ApplicationConfig = {
59
+ providers: [
60
+ // ... other providers ...
61
+ { provide: HTTP_INTERCEPTORS, useClass: MesAuthInterceptor, multi: true }
62
+ ]
63
+ };
64
+ ```
65
+
66
+ 4. Initialize in your app (e.g. `AppComponent` constructor or `AppModule` bootstrap):
38
67
 
39
68
  ```ts
40
69
  // in AppComponent
@@ -107,7 +136,7 @@ Angular helper library to connect to a backend API and SignalR hub to surface th
107
136
  }
108
137
  ```
109
138
 
110
- 4. Build the package for publishing:
139
+ 5. Build the package for publishing:
111
140
 
112
141
  ```bash
113
142
  cd /path/to/mesauth-angular
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './mes-auth.service';
2
- export * from './toast.service';
2
+ export * from './mes-auth.interceptor';
3
3
  export * from './user-profile.component';
4
+ export * from './ma-user.component';
5
+ export * from './notification-badge.component';
6
+ export * from './toast.service';
4
7
  export * from './notification-panel.component';
5
8
  export * from './toast-container.component';
6
- export * from './ma-user.component';
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './mes-auth.service';
2
- export * from './toast.service';
2
+ export * from './mes-auth.interceptor';
3
3
  export * from './user-profile.component';
4
+ export * from './ma-user.component';
5
+ export * from './notification-badge.component';
6
+ export * from './toast.service';
4
7
  export * from './notification-panel.component';
5
8
  export * from './toast-container.component';
6
- export * from './ma-user.component';
@@ -0,0 +1,10 @@
1
+ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import { Router } from '@angular/router';
4
+ import { MesAuthService } from './mes-auth.service';
5
+ export declare class MesAuthInterceptor implements HttpInterceptor {
6
+ private authService;
7
+ private router;
8
+ constructor(authService: MesAuthService, router: Router);
9
+ intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
10
+ }
@@ -0,0 +1,36 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injectable } from '@angular/core';
11
+ import { throwError } from 'rxjs';
12
+ import { catchError } from 'rxjs/operators';
13
+ import { Router } from '@angular/router';
14
+ import { MesAuthService } from './mes-auth.service';
15
+ let MesAuthInterceptor = class MesAuthInterceptor {
16
+ constructor(authService, router) {
17
+ this.authService = authService;
18
+ this.router = router;
19
+ }
20
+ intercept(req, next) {
21
+ return next.handle(req).pipe(catchError((error) => {
22
+ if (error.status === 403) {
23
+ const config = this.authService.getConfig();
24
+ const baseUrl = (config === null || config === void 0 ? void 0 : config.userBaseUrl) || '';
25
+ const returnUrl = encodeURIComponent(window.location.href);
26
+ window.location.href = `${baseUrl}/403?returnUrl=${returnUrl}`;
27
+ }
28
+ return throwError(error);
29
+ }));
30
+ }
31
+ };
32
+ MesAuthInterceptor = __decorate([
33
+ Injectable(),
34
+ __metadata("design:paramtypes", [MesAuthService, Router])
35
+ ], MesAuthInterceptor);
36
+ export { MesAuthInterceptor };
@@ -69,12 +69,12 @@ let UserProfileComponent = class UserProfileComponent {
69
69
  const config = this.authService.getConfig();
70
70
  const baseUrl = (config === null || config === void 0 ? void 0 : config.userBaseUrl) || '';
71
71
  const returnUrl = encodeURIComponent(this.router.url);
72
- this.router.navigateByUrl(`${baseUrl}/login?returnUrl=${returnUrl}`);
72
+ window.location.href = `${baseUrl}/login?returnUrl=${returnUrl}`;
73
73
  }
74
74
  onViewProfile() {
75
75
  const config = this.authService.getConfig();
76
76
  const baseUrl = (config === null || config === void 0 ? void 0 : config.userBaseUrl) || '';
77
- this.router.navigateByUrl(`${baseUrl}/profile`);
77
+ window.location.href = `${baseUrl}/profile`;
78
78
  this.dropdownOpen = false;
79
79
  }
80
80
  onLogout() {
@@ -86,15 +86,15 @@ let UserProfileComponent = class UserProfileComponent {
86
86
  // Navigate to login with return URL
87
87
  const config = this.authService.getConfig();
88
88
  const baseUrl = (config === null || config === void 0 ? void 0 : config.userBaseUrl) || '';
89
- const returnUrl = encodeURIComponent(this.router.url);
90
- this.router.navigateByUrl(`${baseUrl}/login?returnUrl=${returnUrl}`);
89
+ const returnUrl = encodeURIComponent(window.location.href);
90
+ window.location.href = `${baseUrl}/login?returnUrl=${returnUrl}`;
91
91
  },
92
92
  error: (err) => {
93
93
  console.error('Logout error:', err);
94
94
  // Still navigate to login even if logout fails
95
95
  const config = this.authService.getConfig();
96
96
  const baseUrl = (config === null || config === void 0 ? void 0 : config.userBaseUrl) || '';
97
- this.router.navigateByUrl(`${baseUrl}/login`);
97
+ window.location.href = `${baseUrl}/login`;
98
98
  }
99
99
  });
100
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mesauth-angular",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Angular-friendly SignalR notifier + API helper for current user and notifications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",