@acontplus/ng-auth 1.1.0 → 1.1.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.
- package/README.md +66 -47
- package/fesm2022/acontplus-ng-auth.mjs +56 -87
- package/fesm2022/acontplus-ng-auth.mjs.map +1 -1
- package/index.d.ts +29 -50
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @acontplus/ng-auth
|
|
2
2
|
|
|
3
|
-
Acontplus Angular Authentication Module providing comprehensive authentication
|
|
3
|
+
Acontplus Angular Authentication Module providing comprehensive authentication
|
|
4
|
+
and authorization features for Angular applications.
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
@@ -12,26 +13,36 @@ npm install @acontplus/ng-auth
|
|
|
12
13
|
|
|
13
14
|
- **Auth Guard**: Route protection with automatic redirect to login page
|
|
14
15
|
- **Auth Token Service**: JWT token management and authentication state handling
|
|
15
|
-
- **URL Redirection Strategy**: Automatically redirects users back to their
|
|
16
|
-
|
|
16
|
+
- **URL Redirection Strategy**: Automatically redirects users back to their
|
|
17
|
+
intended destination after login
|
|
18
|
+
- **Session Expiry Handling**: Manages session expiry during HTTP requests with
|
|
19
|
+
automatic redirection
|
|
17
20
|
- **CSRF Protection**: Built-in CSRF token management for secure API requests
|
|
18
|
-
- **Token Repository**: Secure token storage and retrieval with local storage
|
|
19
|
-
|
|
21
|
+
- **Token Repository**: Secure token storage and retrieval with local storage
|
|
22
|
+
support
|
|
23
|
+
- **Authentication Use Cases**: Login, register, refresh token, and logout
|
|
24
|
+
functionality
|
|
20
25
|
- **Domain Models**: User domain models and value objects
|
|
21
|
-
- **Clean Architecture**: Organized in domain, application, data, and
|
|
22
|
-
|
|
26
|
+
- **Clean Architecture**: Organized in domain, application, data, and
|
|
27
|
+
presentation layers
|
|
28
|
+
- **Angular Integration**: Seamless integration with Angular Router and HTTP
|
|
29
|
+
client
|
|
23
30
|
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
24
31
|
|
|
25
32
|
## URL Redirection Strategy
|
|
26
33
|
|
|
27
|
-
The module includes a comprehensive URL redirection strategy that ensures users
|
|
34
|
+
The module includes a comprehensive URL redirection strategy that ensures users
|
|
35
|
+
are returned to their intended destination after authentication, even when
|
|
36
|
+
sessions expire.
|
|
28
37
|
|
|
29
38
|
### Components
|
|
30
39
|
|
|
31
40
|
1. **UrlRedirectService** - Manages URL storage and redirection logic
|
|
32
41
|
2. **Enhanced Auth Guard** - Captures URLs before redirecting to login
|
|
33
|
-
3. **Enhanced Login Use Case** - Redirects to stored URLs after successful
|
|
34
|
-
|
|
42
|
+
3. **Enhanced Login Use Case** - Redirects to stored URLs after successful
|
|
43
|
+
authentication
|
|
44
|
+
4. **Auth Redirect Interceptor** - Handles session expiry during HTTP requests
|
|
45
|
+
(optional)
|
|
35
46
|
|
|
36
47
|
### Basic Setup
|
|
37
48
|
|
|
@@ -43,8 +54,8 @@ const routes: Routes = [
|
|
|
43
54
|
{
|
|
44
55
|
path: 'dashboard',
|
|
45
56
|
component: DashboardComponent,
|
|
46
|
-
canActivate: [authGuard] // Automatically captures URL if not authenticated
|
|
47
|
-
}
|
|
57
|
+
canActivate: [authGuard], // Automatically captures URL if not authenticated
|
|
58
|
+
},
|
|
48
59
|
];
|
|
49
60
|
```
|
|
50
61
|
|
|
@@ -59,7 +70,7 @@ export const appConfig: ApplicationConfig = {
|
|
|
59
70
|
provideHttpClient(
|
|
60
71
|
withInterceptors([
|
|
61
72
|
authRedirectInterceptor, // Handles session expiry during API calls
|
|
62
|
-
])
|
|
73
|
+
]),
|
|
63
74
|
),
|
|
64
75
|
],
|
|
65
76
|
};
|
|
@@ -68,11 +79,13 @@ export const appConfig: ApplicationConfig = {
|
|
|
68
79
|
### How It Works
|
|
69
80
|
|
|
70
81
|
**Scenario 1 - Route Protection:**
|
|
82
|
+
|
|
71
83
|
```
|
|
72
84
|
User → /dashboard → Auth Guard → Store URL → Login → Success → Redirect to /dashboard
|
|
73
85
|
```
|
|
74
86
|
|
|
75
87
|
**Scenario 2 - Session Expiry (with interceptor):**
|
|
88
|
+
|
|
76
89
|
```
|
|
77
90
|
User on /reports → API Call → 401 Error → Store URL → Login → Success → Redirect to /reports
|
|
78
91
|
```
|
|
@@ -137,21 +150,19 @@ export class AuthComponent {
|
|
|
137
150
|
|
|
138
151
|
## Login UI Component
|
|
139
152
|
|
|
140
|
-
The library includes a comprehensive login UI component with Material Design
|
|
153
|
+
The library includes a comprehensive login UI component with Material Design
|
|
154
|
+
styling.
|
|
141
155
|
|
|
142
156
|
### Basic Usage
|
|
143
157
|
|
|
144
158
|
```html
|
|
145
|
-
<acp-login
|
|
146
|
-
title="Welcome Back"
|
|
147
|
-
[showRegisterButton]="true">
|
|
148
|
-
</acp-login>
|
|
159
|
+
<acp-login title="Welcome Back" [showRegisterButton]="true"> </acp-login>
|
|
149
160
|
```
|
|
150
161
|
|
|
151
162
|
### Component Features
|
|
152
163
|
|
|
153
164
|
- **Dual Mode Support**: Toggle between login and signup modes
|
|
154
|
-
- **Material Design**: Built with Angular Material components
|
|
165
|
+
- **Material Design**: Built with Angular Material components
|
|
155
166
|
- **Responsive Layout**: Works on desktop and mobile devices
|
|
156
167
|
- **Theme Integration**: Automatically inherits your app's theme colors
|
|
157
168
|
- **Validation**: Built-in form validation with error messaging
|
|
@@ -162,14 +173,15 @@ The library includes a comprehensive login UI component with Material Design sty
|
|
|
162
173
|
### Core Services
|
|
163
174
|
|
|
164
175
|
- **AuthTokenService**: JWT token management and authentication state
|
|
165
|
-
- **UrlRedirectService**: URL storage and redirection management
|
|
176
|
+
- **UrlRedirectService**: URL storage and redirection management
|
|
166
177
|
- **CsrfService**: CSRF token management for secure API requests
|
|
167
178
|
- **TokenRepository**: Secure token storage and retrieval
|
|
168
179
|
|
|
169
180
|
### Guards and Interceptors
|
|
170
181
|
|
|
171
182
|
- **authGuard**: Route protection with automatic URL capture
|
|
172
|
-
- **authRedirectInterceptor**: Session expiry handling during HTTP requests
|
|
183
|
+
- **authRedirectInterceptor**: Session expiry handling during HTTP requests
|
|
184
|
+
(optional)
|
|
173
185
|
|
|
174
186
|
### Use Cases
|
|
175
187
|
|
|
@@ -180,7 +192,8 @@ The library includes a comprehensive login UI component with Material Design sty
|
|
|
180
192
|
|
|
181
193
|
## Architecture
|
|
182
194
|
|
|
183
|
-
This library follows Clean Architecture principles with clear separation of
|
|
195
|
+
This library follows Clean Architecture principles with clear separation of
|
|
196
|
+
concerns organized in domain, application, data, and presentation layers.
|
|
184
197
|
|
|
185
198
|
### Authentication Service
|
|
186
199
|
|
|
@@ -212,7 +225,7 @@ export class LoginComponent {
|
|
|
212
225
|
|
|
213
226
|
async login(credentials: LoginCredentials) {
|
|
214
227
|
const csrfToken = await this.csrfService.getCsrfToken();
|
|
215
|
-
|
|
228
|
+
|
|
216
229
|
// Include CSRF token in your login request
|
|
217
230
|
const response = await this.http.post('/api/login', {
|
|
218
231
|
...credentials,
|
|
@@ -257,11 +270,9 @@ import { NgModule } from '@angular/core';
|
|
|
257
270
|
import { authProviders } from '@acontplus/ng-auth';
|
|
258
271
|
|
|
259
272
|
@NgModule({
|
|
260
|
-
providers: [
|
|
261
|
-
...authProviders
|
|
262
|
-
]
|
|
273
|
+
providers: [...authProviders],
|
|
263
274
|
})
|
|
264
|
-
export class AppModule {
|
|
275
|
+
export class AppModule {}
|
|
265
276
|
```
|
|
266
277
|
|
|
267
278
|
## Running unit tests
|
|
@@ -270,7 +281,8 @@ Run `nx test ng-auth` to execute the unit tests.
|
|
|
270
281
|
|
|
271
282
|
## Login Component
|
|
272
283
|
|
|
273
|
-
The `LoginComponent` provides a flexible, themeable authentication UI component
|
|
284
|
+
The `LoginComponent` provides a flexible, themeable authentication UI component
|
|
285
|
+
with support for custom fields and dynamic content.
|
|
274
286
|
|
|
275
287
|
### Basic Usage
|
|
276
288
|
|
|
@@ -279,12 +291,9 @@ import { LoginComponent } from '@acontplus/ng-auth/ui/login';
|
|
|
279
291
|
|
|
280
292
|
@Component({
|
|
281
293
|
template: `
|
|
282
|
-
<acp-login
|
|
283
|
-
title="Welcome Back"
|
|
284
|
-
[showRegisterButton]="true">
|
|
285
|
-
</acp-login>
|
|
294
|
+
<acp-login title="Welcome Back" [showRegisterButton]="true"> </acp-login>
|
|
286
295
|
`,
|
|
287
|
-
imports: [LoginComponent]
|
|
296
|
+
imports: [LoginComponent],
|
|
288
297
|
})
|
|
289
298
|
export class AuthPageComponent {}
|
|
290
299
|
```
|
|
@@ -318,7 +327,8 @@ export class AuthPageComponent {
|
|
|
318
327
|
```html
|
|
319
328
|
<acp-login
|
|
320
329
|
[additionalSigninControls]="signinExtras"
|
|
321
|
-
[additionalSignupControls]="signupExtras"
|
|
330
|
+
[additionalSignupControls]="signupExtras"
|
|
331
|
+
>
|
|
322
332
|
</acp-login>
|
|
323
333
|
```
|
|
324
334
|
|
|
@@ -334,9 +344,7 @@ Use content projection slots for custom field templates:
|
|
|
334
344
|
<mat-label>Company</mat-label>
|
|
335
345
|
<mat-select formControlName="companyId">
|
|
336
346
|
@for (company of companies; track company.id) {
|
|
337
|
-
<mat-option [value]="company.id">
|
|
338
|
-
{{ company.name }}
|
|
339
|
-
</mat-option>
|
|
347
|
+
<mat-option [value]="company.id"> {{ company.name }} </mat-option>
|
|
340
348
|
}
|
|
341
349
|
</mat-select>
|
|
342
350
|
</mat-form-field>
|
|
@@ -348,9 +356,7 @@ Use content projection slots for custom field templates:
|
|
|
348
356
|
<mat-label>Company</mat-label>
|
|
349
357
|
<mat-select formControlName="companyId" required>
|
|
350
358
|
@for (company of companies; track company.id) {
|
|
351
|
-
<mat-option [value]="company.id">
|
|
352
|
-
{{ company.name }}
|
|
353
|
-
</mat-option>
|
|
359
|
+
<mat-option [value]="company.id"> {{ company.name }} </mat-option>
|
|
354
360
|
}
|
|
355
361
|
</mat-select>
|
|
356
362
|
</mat-form-field>
|
|
@@ -366,7 +372,13 @@ Use content projection slots for custom field templates:
|
|
|
366
372
|
|
|
367
373
|
<mat-form-field class="w-100">
|
|
368
374
|
<mat-label>Validation PIN</mat-label>
|
|
369
|
-
<input
|
|
375
|
+
<input
|
|
376
|
+
matInput
|
|
377
|
+
type="text"
|
|
378
|
+
placeholder="Enter PIN"
|
|
379
|
+
formControlName="validationPin"
|
|
380
|
+
required
|
|
381
|
+
/>
|
|
370
382
|
</mat-form-field>
|
|
371
383
|
</div>
|
|
372
384
|
</acp-login>
|
|
@@ -393,13 +405,17 @@ Customize the footer with dynamic content:
|
|
|
393
405
|
|
|
394
406
|
### Theme Color Inheritance
|
|
395
407
|
|
|
396
|
-
The component uses CSS custom properties to inherit colors from the parent app's
|
|
408
|
+
The component uses CSS custom properties to inherit colors from the parent app's
|
|
409
|
+
theme:
|
|
397
410
|
|
|
398
411
|
- Background gradient: Uses `--mdc-theme-primary` and `--mdc-theme-secondary`
|
|
399
412
|
- Title color: Uses `--mdc-theme-on-surface`
|
|
400
|
-
- Error alerts: Uses `--mdc-theme-error`, `--mdc-theme-error-container`,
|
|
413
|
+
- Error alerts: Uses `--mdc-theme-error`, `--mdc-theme-error-container`,
|
|
414
|
+
`--mdc-theme-on-error-container`
|
|
415
|
+
|
|
416
|
+
Fallback colors use Angular Material's Material Design 3 (M3) neutral color
|
|
417
|
+
tokens:
|
|
401
418
|
|
|
402
|
-
Fallback colors use Angular Material's Material Design 3 (M3) neutral color tokens:
|
|
403
419
|
- Primary: #5c5f5c (M3 neutral primary)
|
|
404
420
|
- Secondary: #79747e (M3 neutral secondary)
|
|
405
421
|
- On surface: #1c1b1f (M3 on-surface)
|
|
@@ -423,7 +439,10 @@ To customize colors, define these CSS variables in your app's global styles:
|
|
|
423
439
|
### Component Inputs
|
|
424
440
|
|
|
425
441
|
- `title: string` - The title displayed in the card header (default: 'Login')
|
|
426
|
-
- `showRegisterButton: boolean` - Whether to show the register button (default:
|
|
427
|
-
|
|
428
|
-
- `
|
|
442
|
+
- `showRegisterButton: boolean` - Whether to show the register button (default:
|
|
443
|
+
true)
|
|
444
|
+
- `additionalSigninControls: Record<string, AbstractControl>` - Additional
|
|
445
|
+
controls for signin form
|
|
446
|
+
- `additionalSignupControls: Record<string, AbstractControl>` - Additional
|
|
447
|
+
controls for signup form
|
|
429
448
|
- `footerContent: TemplateRef<any> | null` - Custom footer template
|