mesauth-angular 0.1.4 → 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 +32 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/ma-user.component.js +1 -2
- package/dist/mes-auth.interceptor.d.ts +10 -0
- package/dist/mes-auth.interceptor.js +36 -0
- package/dist/notification-badge.component.js +2 -2
- package/dist/user-profile.component.js +7 -7
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
139
|
+
5. Build the package for publishing:
|
|
111
140
|
|
|
112
141
|
```bash
|
|
113
142
|
cd /path/to/mesauth-angular
|
|
@@ -160,6 +189,7 @@ A reusable Angular component for displaying the current user's profile informati
|
|
|
160
189
|
If you encounter an error like "The injectable 'MesAuthService' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available," this typically occurs because:
|
|
161
190
|
- The package is being imported directly from source code (e.g., during development) without building it first.
|
|
162
191
|
- The client app is running in AOT (Ahead-of-Time) compilation mode, which requires pre-compiled libraries.
|
|
192
|
+
- **Why JIT is required:** Originally, `MesAuthService` used `@Injectable({ providedIn: 'root' })`, making it a library-provided service. Angular libraries must be built with tools like ng-packagr to generate AOT-compatible code. If not, or if imported from source, the service requires JIT compilation in the client's app. This change (removing `providedIn: 'root'` and requiring manual provision) allows the service to be compiled in your app's context, supporting both JIT and AOT modes.
|
|
163
193
|
|
|
164
194
|
**Solutions:**
|
|
165
195
|
1. **Build the package for production/AOT compatibility:**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './mes-auth.service';
|
|
2
|
-
export * from './
|
|
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 './
|
|
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';
|
|
@@ -5,7 +5,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Component } from '@angular/core';
|
|
8
|
-
import { CommonModule } from '@angular/common';
|
|
9
8
|
import { ToastContainerComponent } from './toast-container.component';
|
|
10
9
|
import { UserProfileComponent } from './user-profile.component';
|
|
11
10
|
import { NotificationPanelComponent } from './notification-panel.component';
|
|
@@ -15,7 +14,7 @@ MaUserComponent = __decorate([
|
|
|
15
14
|
Component({
|
|
16
15
|
selector: 'ma-user',
|
|
17
16
|
standalone: true,
|
|
18
|
-
imports: [
|
|
17
|
+
imports: [ToastContainerComponent, UserProfileComponent, NotificationPanelComponent],
|
|
19
18
|
template: `
|
|
20
19
|
<ma-toast-container></ma-toast-container>
|
|
21
20
|
<div class="user-header">
|
|
@@ -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 };
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Component, Output, EventEmitter } from '@angular/core';
|
|
11
|
-
import {
|
|
11
|
+
import { NgIf } from '@angular/common';
|
|
12
12
|
import { MesAuthService } from './mes-auth.service';
|
|
13
13
|
import { Subject } from 'rxjs';
|
|
14
14
|
import { takeUntil } from 'rxjs/operators';
|
|
@@ -52,7 +52,7 @@ NotificationBadgeComponent = __decorate([
|
|
|
52
52
|
Component({
|
|
53
53
|
selector: 'ma-notification-badge',
|
|
54
54
|
standalone: true,
|
|
55
|
-
imports: [
|
|
55
|
+
imports: [NgIf],
|
|
56
56
|
template: `
|
|
57
57
|
<button class="notification-btn" (click)="onNotificationClick()" title="Notifications">
|
|
58
58
|
<span class="icon">🔔</span>
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Component, Output, EventEmitter } from '@angular/core';
|
|
11
|
-
import {
|
|
11
|
+
import { NgIf } from '@angular/common';
|
|
12
12
|
import { Router } from '@angular/router';
|
|
13
13
|
import { MesAuthService } from './mes-auth.service';
|
|
14
14
|
import { Subject } from 'rxjs';
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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(
|
|
90
|
-
|
|
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
|
-
|
|
97
|
+
window.location.href = `${baseUrl}/login`;
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
}
|
|
@@ -110,7 +110,7 @@ UserProfileComponent = __decorate([
|
|
|
110
110
|
Component({
|
|
111
111
|
selector: 'ma-user-profile',
|
|
112
112
|
standalone: true,
|
|
113
|
-
imports: [
|
|
113
|
+
imports: [NgIf],
|
|
114
114
|
template: `
|
|
115
115
|
<div class="user-profile-container">
|
|
116
116
|
<!-- Not logged in -->
|