mesauth-angular 0.2.14 → 0.2.20
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 +139 -61
- package/dist/README.md +139 -61
- package/dist/{fesm2020 → fesm2022}/mesauth-angular.mjs +702 -662
- package/dist/fesm2022/mesauth-angular.mjs.map +1 -0
- package/dist/index.d.ts +269 -9
- package/package.json +12 -12
- package/dist/esm2020/index.mjs +0 -10
- package/dist/esm2020/ma-user.component.mjs +0 -32
- package/dist/esm2020/mes-auth.interceptor.mjs +0 -29
- package/dist/esm2020/mes-auth.module.mjs +0 -23
- package/dist/esm2020/mes-auth.service.mjs +0 -146
- package/dist/esm2020/mesauth-angular.mjs +0 -5
- package/dist/esm2020/notification-badge.component.mjs +0 -71
- package/dist/esm2020/notification-panel.component.mjs +0 -333
- package/dist/esm2020/theme.service.mjs +0 -63
- package/dist/esm2020/toast-container.component.mjs +0 -83
- package/dist/esm2020/toast.service.mjs +0 -41
- package/dist/esm2020/user-profile.component.mjs +0 -223
- package/dist/fesm2015/mesauth-angular.mjs +0 -1012
- package/dist/fesm2015/mesauth-angular.mjs.map +0 -1
- package/dist/fesm2020/mesauth-angular.mjs.map +0 -1
- package/dist/ma-user.component.d.ts +0 -8
- package/dist/mes-auth.interceptor.d.ts +0 -13
- package/dist/mes-auth.module.d.ts +0 -6
- package/dist/mes-auth.service.d.ts +0 -102
- package/dist/notification-badge.component.d.ts +0 -20
- package/dist/notification-panel.component.d.ts +0 -36
- package/dist/package.json +0 -52
- package/dist/theme.service.d.ts +0 -19
- package/dist/toast-container.component.d.ts +0 -18
- package/dist/toast.service.d.ts +0 -18
- package/dist/user-profile.component.d.ts +0 -31
package/README.md
CHANGED
|
@@ -121,76 +121,69 @@ Avatars are loaded directly from your API using the pattern: `GET /auth/{userId}
|
|
|
121
121
|
};
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
4. Initialize in your app (
|
|
124
|
+
4. Initialize in your app (recommended in `AppComponent` constructor):
|
|
125
|
+
|
|
126
|
+
**⚠️ IMPORTANT:** Starting from v0.2.16, `MesAuthService` requires `HttpClient` and optionally `Router` to be passed to the `init()` method. This prevents dependency injection timing issues.
|
|
125
127
|
|
|
126
128
|
```ts
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
// In AppComponent constructor (recommended)
|
|
130
|
+
import { HttpClient } from '@angular/common/http';
|
|
131
|
+
import { Router } from '@angular/router';
|
|
132
|
+
import { inject } from '@angular/core';
|
|
133
|
+
import { MesAuthService } from 'mesauth-angular';
|
|
134
|
+
|
|
135
|
+
export class AppComponent {
|
|
136
|
+
readonly #mesAuthService = inject(MesAuthService);
|
|
137
|
+
readonly #router = inject(Router);
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
constructor() {
|
|
140
|
+
// Initialize MesAuth with HttpClient and Router
|
|
141
|
+
this.#mesAuthService.init(
|
|
142
|
+
{
|
|
143
|
+
apiBaseUrl: 'https://api.example.com',
|
|
144
|
+
withCredentials: true,
|
|
145
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
146
|
+
},
|
|
147
|
+
inject(HttpClient), // Required: pass HttpClient
|
|
148
|
+
this.#router // Optional: pass Router for automatic user refresh on navigation
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// Subscribe to observables
|
|
152
|
+
this.#mesAuthService.currentUser$.subscribe(user => console.log('user', user));
|
|
153
|
+
this.#mesAuthService.notifications$.subscribe(n => console.log('notif', n));
|
|
154
|
+
}
|
|
137
155
|
}
|
|
138
156
|
```
|
|
139
157
|
|
|
140
|
-
|
|
158
|
+
**Why this change?**
|
|
159
|
+
- Previous versions injected `HttpClient` and `Router` directly in the service constructor
|
|
160
|
+
- This caused `NG0203` injection context errors during route loading and early bootstrap
|
|
161
|
+
- The new pattern delays dependency access until after the app is fully initialized
|
|
141
162
|
|
|
142
|
-
|
|
143
|
-
// In a standalone component or function
|
|
144
|
-
const mesAuth = inject(MesAuthService);
|
|
145
|
-
mesAuth.init({
|
|
146
|
-
apiBaseUrl: 'https://api.example.com',
|
|
147
|
-
withCredentials: true,
|
|
148
|
-
userBaseUrl: 'https://api.example.com/users'
|
|
149
|
-
});
|
|
163
|
+
**For Module-based Apps:**
|
|
150
164
|
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
```ts
|
|
166
|
+
// In AppComponent
|
|
167
|
+
import { HttpClient } from '@angular/common/http';
|
|
168
|
+
import { Router } from '@angular/router';
|
|
169
|
+
|
|
170
|
+
constructor(
|
|
171
|
+
private mesAuth: MesAuthService,
|
|
172
|
+
private http: HttpClient,
|
|
173
|
+
private router: Router
|
|
174
|
+
) {
|
|
175
|
+
this.mesAuth.init(
|
|
176
|
+
{
|
|
177
|
+
apiBaseUrl: 'https://api.example.com',
|
|
178
|
+
withCredentials: true,
|
|
179
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
180
|
+
},
|
|
181
|
+
this.http, // Required
|
|
182
|
+
this.router // Optional
|
|
183
|
+
);
|
|
184
|
+
}
|
|
153
185
|
```
|
|
154
186
|
|
|
155
|
-
**For Standalone Apps (using `bootstrapApplication`):**
|
|
156
|
-
- After providing the service as above, initialize it using `APP_INITIALIZER` in your `app.config.ts` for app-wide setup, or in the root component.
|
|
157
|
-
- Example in `app.config.ts` (add to providers):
|
|
158
|
-
|
|
159
|
-
```ts
|
|
160
|
-
import { APP_INITIALIZER } from '@angular/core';
|
|
161
|
-
import { MesAuthService } from 'mesauth-angular';
|
|
162
|
-
|
|
163
|
-
export const appConfig: ApplicationConfig = {
|
|
164
|
-
providers: [
|
|
165
|
-
// ... other providers ...
|
|
166
|
-
MesAuthService,
|
|
167
|
-
{
|
|
168
|
-
provide: APP_INITIALIZER,
|
|
169
|
-
useFactory: (mesAuth: MesAuthService) => () => {
|
|
170
|
-
mesAuth.init({
|
|
171
|
-
apiBaseUrl: 'https://api.example.com',
|
|
172
|
-
withCredentials: true,
|
|
173
|
-
userBaseUrl: 'https://api.example.com/users'
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
deps: [MesAuthService],
|
|
177
|
-
multi: true
|
|
178
|
-
}
|
|
179
|
-
]
|
|
180
|
-
};
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
- Then, in your root component (e.g., `AppComponent`), subscribe to observables as usual:
|
|
184
|
-
|
|
185
|
-
```ts
|
|
186
|
-
// In AppComponent (standalone)
|
|
187
|
-
constructor() {
|
|
188
|
-
const mesAuth = inject(MesAuthService);
|
|
189
|
-
mesAuth.currentUser$.subscribe(user => console.log('user', user));
|
|
190
|
-
mesAuth.notifications$.subscribe(n => console.log('notif', n));
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
187
|
5. Build the package for publishing:
|
|
195
188
|
|
|
196
189
|
```bash
|
|
@@ -258,7 +251,25 @@ A standalone component for displaying a slide-out notification panel with real-t
|
|
|
258
251
|
|
|
259
252
|
## Changelog
|
|
260
253
|
|
|
261
|
-
### v0.2.
|
|
254
|
+
### v0.2.18 (Latest)
|
|
255
|
+
- 🔗 **Interceptor Improvement**: `MesAuthInterceptor` now uses `router.url` instead of `window.location.href` for cleaner returnUrl parameters
|
|
256
|
+
- 📍 **Shorter URLs**: Return URLs are now relative paths (`/dashboard`) instead of full URLs (`https://domain.com/dashboard`)
|
|
257
|
+
- 🔄 **Better Fallback**: Falls back to `window.location.pathname + search` if router URL is unavailable
|
|
258
|
+
|
|
259
|
+
### v0.2.17
|
|
260
|
+
- 🐛 **ViewChild Fix**: Fixed `MaUserComponent` ViewChild query error by adding `AfterViewInit` lifecycle and `{ static: false }` option
|
|
261
|
+
- ✅ **Error Handling**: Added graceful error handling for 401/403 responses on auth endpoints (silent handling when user not logged in)
|
|
262
|
+
- 🧹 **Clean Console**: Auth errors no longer pollute the console - expected authentication failures are handled silently
|
|
263
|
+
- 🛡️ **Null Safety**: Added null check in `onNotificationRead()` to prevent errors when userProfile is not yet initialized
|
|
264
|
+
|
|
265
|
+
### v0.2.16
|
|
266
|
+
- 🔧 **Breaking Change**: `init()` method now requires `HttpClient` and optionally `Router` as parameters
|
|
267
|
+
- 🚫 **Injection Fix**: Removed `HttpClient` and `Router` from service constructor to prevent `NG0203` injection context errors
|
|
268
|
+
- ⚡ **Improved Initialization**: Dependencies are now passed explicitly to `init()` method, resolving timing issues during route loading
|
|
269
|
+
- 📝 **API Change**: `init(config: MesAuthConfig, httpClient: HttpClient, router?: Router)`
|
|
270
|
+
- 🎯 **Why**: Fixes dependency injection errors that occurred during lazy route loading and early bootstrap phases
|
|
271
|
+
|
|
272
|
+
### v0.2.13
|
|
262
273
|
- 🎨 **Notification Format**: Cleaned up notification title format by removing redundant `[sourceAppName]` prefix
|
|
263
274
|
- 📱 **Improved Layout**: Source app name now displayed separately in metadata row for better organization
|
|
264
275
|
- 🔔 **Consistent Toasts**: Toast notifications also updated to use clean title format without app name prefix
|
|
@@ -326,6 +337,73 @@ A standalone component for displaying a slide-out notification panel with real-t
|
|
|
326
337
|
- Avatar endpoint: `GET {apiBaseUrl}/auth/{userId}/avatar`
|
|
327
338
|
- SignalR events used: `ReceiveNotification` (adjust to your backend).
|
|
328
339
|
|
|
340
|
+
## Migration Guide
|
|
341
|
+
|
|
342
|
+
### Upgrading from v0.2.15 or earlier to v0.2.16+
|
|
343
|
+
|
|
344
|
+
The initialization pattern has changed to fix dependency injection timing issues. Follow these steps:
|
|
345
|
+
|
|
346
|
+
**Before (v0.2.15 and earlier):**
|
|
347
|
+
```ts
|
|
348
|
+
constructor(private mesAuth: MesAuthService) {
|
|
349
|
+
this.mesAuth.init({
|
|
350
|
+
apiBaseUrl: 'https://api.example.com',
|
|
351
|
+
withCredentials: true,
|
|
352
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**After (v0.2.16+):**
|
|
358
|
+
```ts
|
|
359
|
+
import { HttpClient } from '@angular/common/http';
|
|
360
|
+
import { Router } from '@angular/router';
|
|
361
|
+
import { inject } from '@angular/core';
|
|
362
|
+
|
|
363
|
+
export class AppComponent {
|
|
364
|
+
readonly #mesAuthService = inject(MesAuthService);
|
|
365
|
+
readonly #router = inject(Router);
|
|
366
|
+
|
|
367
|
+
constructor() {
|
|
368
|
+
// Pass HttpClient and Router to init()
|
|
369
|
+
this.#mesAuthService.init(
|
|
370
|
+
{
|
|
371
|
+
apiBaseUrl: 'https://api.example.com',
|
|
372
|
+
withCredentials: true,
|
|
373
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
374
|
+
},
|
|
375
|
+
inject(HttpClient), // Required: add this parameter
|
|
376
|
+
this.#router // Optional: add this parameter for auto user refresh
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**For module-based apps:**
|
|
383
|
+
```ts
|
|
384
|
+
constructor(
|
|
385
|
+
private mesAuth: MesAuthService,
|
|
386
|
+
private http: HttpClient, // Add this
|
|
387
|
+
private router: Router // Add this (optional)
|
|
388
|
+
) {
|
|
389
|
+
this.mesAuth.init(
|
|
390
|
+
{
|
|
391
|
+
apiBaseUrl: 'https://api.example.com',
|
|
392
|
+
withCredentials: true,
|
|
393
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
394
|
+
},
|
|
395
|
+
this.http, // Add this parameter
|
|
396
|
+
this.router // Add this parameter (optional)
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**What changed and why:**
|
|
402
|
+
- `HttpClient` is now required as the 2nd parameter to `init()`
|
|
403
|
+
- `Router` is optional as the 3rd parameter (recommended for SPA user refresh)
|
|
404
|
+
- This fixes `NG0203` injection errors that occurred during route lazy-loading
|
|
405
|
+
- The service constructor is now empty - all dependencies are passed to `init()`
|
|
406
|
+
|
|
329
407
|
## Troubleshooting
|
|
330
408
|
|
|
331
409
|
### JIT Compiler Error in Production or AOT Mode
|
package/dist/README.md
CHANGED
|
@@ -121,76 +121,69 @@ Avatars are loaded directly from your API using the pattern: `GET /auth/{userId}
|
|
|
121
121
|
};
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
4. Initialize in your app (
|
|
124
|
+
4. Initialize in your app (recommended in `AppComponent` constructor):
|
|
125
|
+
|
|
126
|
+
**⚠️ IMPORTANT:** Starting from v0.2.16, `MesAuthService` requires `HttpClient` and optionally `Router` to be passed to the `init()` method. This prevents dependency injection timing issues.
|
|
125
127
|
|
|
126
128
|
```ts
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
// In AppComponent constructor (recommended)
|
|
130
|
+
import { HttpClient } from '@angular/common/http';
|
|
131
|
+
import { Router } from '@angular/router';
|
|
132
|
+
import { inject } from '@angular/core';
|
|
133
|
+
import { MesAuthService } from 'mesauth-angular';
|
|
134
|
+
|
|
135
|
+
export class AppComponent {
|
|
136
|
+
readonly #mesAuthService = inject(MesAuthService);
|
|
137
|
+
readonly #router = inject(Router);
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
constructor() {
|
|
140
|
+
// Initialize MesAuth with HttpClient and Router
|
|
141
|
+
this.#mesAuthService.init(
|
|
142
|
+
{
|
|
143
|
+
apiBaseUrl: 'https://api.example.com',
|
|
144
|
+
withCredentials: true,
|
|
145
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
146
|
+
},
|
|
147
|
+
inject(HttpClient), // Required: pass HttpClient
|
|
148
|
+
this.#router // Optional: pass Router for automatic user refresh on navigation
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// Subscribe to observables
|
|
152
|
+
this.#mesAuthService.currentUser$.subscribe(user => console.log('user', user));
|
|
153
|
+
this.#mesAuthService.notifications$.subscribe(n => console.log('notif', n));
|
|
154
|
+
}
|
|
137
155
|
}
|
|
138
156
|
```
|
|
139
157
|
|
|
140
|
-
|
|
158
|
+
**Why this change?**
|
|
159
|
+
- Previous versions injected `HttpClient` and `Router` directly in the service constructor
|
|
160
|
+
- This caused `NG0203` injection context errors during route loading and early bootstrap
|
|
161
|
+
- The new pattern delays dependency access until after the app is fully initialized
|
|
141
162
|
|
|
142
|
-
|
|
143
|
-
// In a standalone component or function
|
|
144
|
-
const mesAuth = inject(MesAuthService);
|
|
145
|
-
mesAuth.init({
|
|
146
|
-
apiBaseUrl: 'https://api.example.com',
|
|
147
|
-
withCredentials: true,
|
|
148
|
-
userBaseUrl: 'https://api.example.com/users'
|
|
149
|
-
});
|
|
163
|
+
**For Module-based Apps:**
|
|
150
164
|
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
```ts
|
|
166
|
+
// In AppComponent
|
|
167
|
+
import { HttpClient } from '@angular/common/http';
|
|
168
|
+
import { Router } from '@angular/router';
|
|
169
|
+
|
|
170
|
+
constructor(
|
|
171
|
+
private mesAuth: MesAuthService,
|
|
172
|
+
private http: HttpClient,
|
|
173
|
+
private router: Router
|
|
174
|
+
) {
|
|
175
|
+
this.mesAuth.init(
|
|
176
|
+
{
|
|
177
|
+
apiBaseUrl: 'https://api.example.com',
|
|
178
|
+
withCredentials: true,
|
|
179
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
180
|
+
},
|
|
181
|
+
this.http, // Required
|
|
182
|
+
this.router // Optional
|
|
183
|
+
);
|
|
184
|
+
}
|
|
153
185
|
```
|
|
154
186
|
|
|
155
|
-
**For Standalone Apps (using `bootstrapApplication`):**
|
|
156
|
-
- After providing the service as above, initialize it using `APP_INITIALIZER` in your `app.config.ts` for app-wide setup, or in the root component.
|
|
157
|
-
- Example in `app.config.ts` (add to providers):
|
|
158
|
-
|
|
159
|
-
```ts
|
|
160
|
-
import { APP_INITIALIZER } from '@angular/core';
|
|
161
|
-
import { MesAuthService } from 'mesauth-angular';
|
|
162
|
-
|
|
163
|
-
export const appConfig: ApplicationConfig = {
|
|
164
|
-
providers: [
|
|
165
|
-
// ... other providers ...
|
|
166
|
-
MesAuthService,
|
|
167
|
-
{
|
|
168
|
-
provide: APP_INITIALIZER,
|
|
169
|
-
useFactory: (mesAuth: MesAuthService) => () => {
|
|
170
|
-
mesAuth.init({
|
|
171
|
-
apiBaseUrl: 'https://api.example.com',
|
|
172
|
-
withCredentials: true,
|
|
173
|
-
userBaseUrl: 'https://api.example.com/users'
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
deps: [MesAuthService],
|
|
177
|
-
multi: true
|
|
178
|
-
}
|
|
179
|
-
]
|
|
180
|
-
};
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
- Then, in your root component (e.g., `AppComponent`), subscribe to observables as usual:
|
|
184
|
-
|
|
185
|
-
```ts
|
|
186
|
-
// In AppComponent (standalone)
|
|
187
|
-
constructor() {
|
|
188
|
-
const mesAuth = inject(MesAuthService);
|
|
189
|
-
mesAuth.currentUser$.subscribe(user => console.log('user', user));
|
|
190
|
-
mesAuth.notifications$.subscribe(n => console.log('notif', n));
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
187
|
5. Build the package for publishing:
|
|
195
188
|
|
|
196
189
|
```bash
|
|
@@ -258,7 +251,25 @@ A standalone component for displaying a slide-out notification panel with real-t
|
|
|
258
251
|
|
|
259
252
|
## Changelog
|
|
260
253
|
|
|
261
|
-
### v0.2.
|
|
254
|
+
### v0.2.18 (Latest)
|
|
255
|
+
- 🔗 **Interceptor Improvement**: `MesAuthInterceptor` now uses `router.url` instead of `window.location.href` for cleaner returnUrl parameters
|
|
256
|
+
- 📍 **Shorter URLs**: Return URLs are now relative paths (`/dashboard`) instead of full URLs (`https://domain.com/dashboard`)
|
|
257
|
+
- 🔄 **Better Fallback**: Falls back to `window.location.pathname + search` if router URL is unavailable
|
|
258
|
+
|
|
259
|
+
### v0.2.17
|
|
260
|
+
- 🐛 **ViewChild Fix**: Fixed `MaUserComponent` ViewChild query error by adding `AfterViewInit` lifecycle and `{ static: false }` option
|
|
261
|
+
- ✅ **Error Handling**: Added graceful error handling for 401/403 responses on auth endpoints (silent handling when user not logged in)
|
|
262
|
+
- 🧹 **Clean Console**: Auth errors no longer pollute the console - expected authentication failures are handled silently
|
|
263
|
+
- 🛡️ **Null Safety**: Added null check in `onNotificationRead()` to prevent errors when userProfile is not yet initialized
|
|
264
|
+
|
|
265
|
+
### v0.2.16
|
|
266
|
+
- 🔧 **Breaking Change**: `init()` method now requires `HttpClient` and optionally `Router` as parameters
|
|
267
|
+
- 🚫 **Injection Fix**: Removed `HttpClient` and `Router` from service constructor to prevent `NG0203` injection context errors
|
|
268
|
+
- ⚡ **Improved Initialization**: Dependencies are now passed explicitly to `init()` method, resolving timing issues during route loading
|
|
269
|
+
- 📝 **API Change**: `init(config: MesAuthConfig, httpClient: HttpClient, router?: Router)`
|
|
270
|
+
- 🎯 **Why**: Fixes dependency injection errors that occurred during lazy route loading and early bootstrap phases
|
|
271
|
+
|
|
272
|
+
### v0.2.13
|
|
262
273
|
- 🎨 **Notification Format**: Cleaned up notification title format by removing redundant `[sourceAppName]` prefix
|
|
263
274
|
- 📱 **Improved Layout**: Source app name now displayed separately in metadata row for better organization
|
|
264
275
|
- 🔔 **Consistent Toasts**: Toast notifications also updated to use clean title format without app name prefix
|
|
@@ -326,6 +337,73 @@ A standalone component for displaying a slide-out notification panel with real-t
|
|
|
326
337
|
- Avatar endpoint: `GET {apiBaseUrl}/auth/{userId}/avatar`
|
|
327
338
|
- SignalR events used: `ReceiveNotification` (adjust to your backend).
|
|
328
339
|
|
|
340
|
+
## Migration Guide
|
|
341
|
+
|
|
342
|
+
### Upgrading from v0.2.15 or earlier to v0.2.16+
|
|
343
|
+
|
|
344
|
+
The initialization pattern has changed to fix dependency injection timing issues. Follow these steps:
|
|
345
|
+
|
|
346
|
+
**Before (v0.2.15 and earlier):**
|
|
347
|
+
```ts
|
|
348
|
+
constructor(private mesAuth: MesAuthService) {
|
|
349
|
+
this.mesAuth.init({
|
|
350
|
+
apiBaseUrl: 'https://api.example.com',
|
|
351
|
+
withCredentials: true,
|
|
352
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**After (v0.2.16+):**
|
|
358
|
+
```ts
|
|
359
|
+
import { HttpClient } from '@angular/common/http';
|
|
360
|
+
import { Router } from '@angular/router';
|
|
361
|
+
import { inject } from '@angular/core';
|
|
362
|
+
|
|
363
|
+
export class AppComponent {
|
|
364
|
+
readonly #mesAuthService = inject(MesAuthService);
|
|
365
|
+
readonly #router = inject(Router);
|
|
366
|
+
|
|
367
|
+
constructor() {
|
|
368
|
+
// Pass HttpClient and Router to init()
|
|
369
|
+
this.#mesAuthService.init(
|
|
370
|
+
{
|
|
371
|
+
apiBaseUrl: 'https://api.example.com',
|
|
372
|
+
withCredentials: true,
|
|
373
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
374
|
+
},
|
|
375
|
+
inject(HttpClient), // Required: add this parameter
|
|
376
|
+
this.#router // Optional: add this parameter for auto user refresh
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**For module-based apps:**
|
|
383
|
+
```ts
|
|
384
|
+
constructor(
|
|
385
|
+
private mesAuth: MesAuthService,
|
|
386
|
+
private http: HttpClient, // Add this
|
|
387
|
+
private router: Router // Add this (optional)
|
|
388
|
+
) {
|
|
389
|
+
this.mesAuth.init(
|
|
390
|
+
{
|
|
391
|
+
apiBaseUrl: 'https://api.example.com',
|
|
392
|
+
withCredentials: true,
|
|
393
|
+
userBaseUrl: 'https://api.example.com/users'
|
|
394
|
+
},
|
|
395
|
+
this.http, // Add this parameter
|
|
396
|
+
this.router // Add this parameter (optional)
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**What changed and why:**
|
|
402
|
+
- `HttpClient` is now required as the 2nd parameter to `init()`
|
|
403
|
+
- `Router` is optional as the 3rd parameter (recommended for SPA user refresh)
|
|
404
|
+
- This fixes `NG0203` injection errors that occurred during route lazy-loading
|
|
405
|
+
- The service constructor is now empty - all dependencies are passed to `init()`
|
|
406
|
+
|
|
329
407
|
## Troubleshooting
|
|
330
408
|
|
|
331
409
|
### JIT Compiler Error in Production or AOT Mode
|