@acontplus/ng-auth 1.0.0 → 1.0.1

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 ADDED
@@ -0,0 +1,128 @@
1
+ # @acontplus/ng-auth
2
+
3
+ Acontplus Angular Authentication Module providing comprehensive authentication and authorization features for Angular applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @acontplus/ng-auth
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Auth Guard**: Route protection with automatic redirect to login page
14
+ - **Auth Token Service**: JWT token management and authentication state handling
15
+ - **CSRF Protection**: Built-in CSRF token management for secure API requests
16
+ - **Token Repository**: Secure token storage and retrieval with local storage support
17
+ - **Authentication Use Cases**: Login, register, refresh token, and logout functionality
18
+ - **Domain Models**: User domain models and value objects
19
+ - **Clean Architecture**: Organized in domain, application, data, and presentation layers
20
+ - **Angular Integration**: Seamless integration with Angular Router and HTTP client
21
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
22
+
23
+ ## Usage
24
+
25
+ ### Route Protection with Auth Guard
26
+
27
+ ```typescript
28
+ import { authGuard } from '@acontplus/ng-auth';
29
+
30
+ const routes: Routes = [
31
+ {
32
+ path: 'dashboard',
33
+ component: DashboardComponent,
34
+ canActivate: [authGuard]
35
+ },
36
+ {
37
+ path: 'admin',
38
+ component: AdminComponent,
39
+ canActivate: [authGuard]
40
+ }
41
+ ];
42
+ ```
43
+
44
+ ### Authentication Service
45
+
46
+ ```typescript
47
+ import { AuthTokenService } from '@acontplus/ng-auth';
48
+
49
+ @Component({...})
50
+ export class MyComponent {
51
+ constructor(private authService: AuthTokenService) {}
52
+
53
+ isUserAuthenticated(): boolean {
54
+ return this.authService.isAuthenticated();
55
+ }
56
+
57
+ getAuthToken(): string | null {
58
+ return this.authService.getToken();
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### CSRF Protection
64
+
65
+ ```typescript
66
+ import { CsrfService } from '@acontplus/ng-auth';
67
+
68
+ @Component({...})
69
+ export class LoginComponent {
70
+ constructor(private csrfService: CsrfService) {}
71
+
72
+ async login(credentials: LoginCredentials) {
73
+ const csrfToken = await this.csrfService.getCsrfToken();
74
+
75
+ // Include CSRF token in your login request
76
+ const response = await this.http.post('/api/login', {
77
+ ...credentials,
78
+ csrfToken
79
+ });
80
+ }
81
+ }
82
+ ```
83
+
84
+ ### Using Authentication Use Cases
85
+
86
+ ```typescript
87
+ import { LoginUseCase, LogoutUseCase } from '@acontplus/ng-auth';
88
+
89
+ @Component({...})
90
+ export class AuthComponent {
91
+ constructor(
92
+ private loginUseCase: LoginUseCase,
93
+ private logoutUseCase: LogoutUseCase
94
+ ) {}
95
+
96
+ async login(credentials: LoginCredentials) {
97
+ try {
98
+ const result = await this.loginUseCase.execute(credentials);
99
+ // Handle successful login
100
+ } catch (error) {
101
+ // Handle login error
102
+ }
103
+ }
104
+
105
+ async logout() {
106
+ await this.logoutUseCase.execute();
107
+ // Handle logout
108
+ }
109
+ }
110
+ ```
111
+
112
+ ### Module Setup
113
+
114
+ ```typescript
115
+ import { NgModule } from '@angular/core';
116
+ import { authProviders } from '@acontplus/ng-auth';
117
+
118
+ @NgModule({
119
+ providers: [
120
+ ...authProviders
121
+ ]
122
+ })
123
+ export class AppModule { }
124
+ ```
125
+
126
+ ## Running unit tests
127
+
128
+ Run `nx test ng-auth` to execute the unit tests.