@processpuzzle/auth 0.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.
Files changed (2) hide show
  1. package/README.md +476 -0
  2. package/package.json +37 -0
package/README.md ADDED
@@ -0,0 +1,476 @@
1
+ # @processpuzzle/auth
2
+ ![Build and Test](https://github.com/ZsZs/processpuzzle/actions/workflows/build-auth.yml/badge.svg)
3
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=processpuzzle_auth&metric=alert_status)](https://sonarcloud.io/summary?id=processpuzzle_auth)
4
+ [![Node version](https://img.shields.io/npm/v/%40processpuzzle%2Fauth?style=flat)](https://www.npmjs.com/package/@processpuzzle/auth)
5
+
6
+ The Auth library provides widgets and services for authentication and authorization. It offers:
7
+ - [authentication menu](#auth-button)
8
+ - [login](#login-component)
9
+ - [logout](#logout-component)
10
+ - [registration](#registration-component)
11
+ - [user profile](#my-profile-component)
12
+ - [auth service](#authentication-service)
13
+ - [auth guard](#authentication-guard)
14
+
15
+ ## Auth Button
16
+
17
+ The `AuthButtonComponent` is a versatile authentication button that displays different options based on the user's authentication status. It provides a clean, intuitive interface for users to access authentication-related features.
18
+
19
+ ### Features
20
+
21
+ - Displays a person icon button that opens a dropdown menu
22
+ - Dynamically shows different menu options based on authentication status
23
+ - When not authenticated, shows Login and Register options
24
+ - When authenticated, shows My Profile and Logout options
25
+ - Integrates with Angular Router for navigation to auth pages
26
+ - Uses Angular Material components for a consistent UI experience
27
+
28
+ ### Usage
29
+
30
+ Simply add the component to your template:
31
+
32
+ ```html
33
+ <pp-auth-button></pp-auth-button>
34
+ ```
35
+
36
+ The component automatically detects the user's authentication status using the `AuthService` and displays the appropriate menu options.
37
+
38
+ #### Example: Adding to a toolbar
39
+
40
+ ```html
41
+ <mat-toolbar>
42
+ <span>My App</span>
43
+ <span class="spacer"></span>
44
+ <pp-auth-button></pp-auth-button>
45
+ </mat-toolbar>
46
+ ```
47
+
48
+ ### API Reference
49
+
50
+ #### Selector
51
+ `pp-auth-button`
52
+
53
+ #### Dependencies
54
+ - `AuthService` - Used to determine the user's authentication status
55
+ - Angular Material components (MatIconButton, MatMenu, MatMenuItem)
56
+ - Angular Router - For navigation to auth-related routes
57
+
58
+ #### Properties
59
+ - `isAuthenticated` - A computed signal that reflects the current authentication status
60
+ - `routes` - The filtered list of authentication routes with titles
61
+
62
+ ### Styling
63
+
64
+ The component uses Angular Material styling by default. You can target the component with CSS using the `.auth-button` class:
65
+
66
+ ```css
67
+ .auth-button {
68
+ /* Your custom styles */
69
+ }
70
+ ```
71
+
72
+ ### Customization
73
+
74
+ The component uses routes defined in `authRoutes` from the auth library. Each route can have the following properties:
75
+
76
+ - `path` - The route path
77
+ - `component` - The component to render
78
+ - `title` - The display name in the menu
79
+ - `data.icon` - The Material icon to display
80
+ - `data.authToggle` - Whether to show the item when authenticated (false) or not authenticated (true)
81
+
82
+
83
+ ## Login Component
84
+
85
+ The `LoginComponent` provides a user-friendly interface for authentication, allowing users to sign in with their email and password or through Google authentication. It includes form validation, error handling, and visual feedback during the authentication process.
86
+
87
+ ### Features
88
+
89
+ - Clean, responsive login form with Material Design styling
90
+ - Email and password authentication with Firebase
91
+ - Google sign-in integration
92
+ - Real-time form validation with error messages
93
+ - Password visibility toggle
94
+ - Loading state indication during authentication
95
+ - Error handling with user-friendly messages
96
+ - Redirect to home page after successful login
97
+ - Link to registration page for new users
98
+
99
+ ### Usage
100
+
101
+ Add the component to your routes configuration:
102
+
103
+ ```typescript
104
+ const routes: Routes = [
105
+ { path: 'login', component: LoginComponent }
106
+ ];
107
+ ```
108
+
109
+ Then navigate to the login route:
110
+
111
+ ```typescript
112
+ // In your component
113
+ constructor(private router: Router) {}
114
+
115
+ navigateToLogin() {
116
+ this.router.navigate(['/login']);
117
+ }
118
+ ```
119
+
120
+ Or create a link in your template:
121
+
122
+ ```html
123
+ <a routerLink="/login">Login</a>
124
+ ```
125
+
126
+ ### API Reference
127
+
128
+ #### Selector
129
+ `pp-login`
130
+
131
+ #### Dependencies
132
+ - `AuthService` - Used for authentication operations
133
+ - Angular Material components (MatFormField, MatInput, MatButton, etc.)
134
+ - Angular Reactive Forms - For form handling and validation
135
+ - Firebase Authentication - For authentication operations
136
+
137
+ #### Properties
138
+ - `loginForm` - FormGroup that manages the login form state and validation
139
+ - `isLoading` - Signal that indicates whether an authentication operation is in progress
140
+ - `errorMessage` - Signal that contains any error message to display
141
+ - `hidePassword` - Boolean that controls password visibility
142
+
143
+ #### Methods
144
+ - `onSubmit()` - Handles form submission for email/password login
145
+ - `signInWithGoogle()` - Initiates Google authentication
146
+ - `getErrorMessage(errorCode: string)` - Converts Firebase error codes to user-friendly messages
147
+
148
+ ### Styling
149
+
150
+ The component uses Angular Material styling with custom CSS for layout. You can target the component with CSS using the `.login-container` class:
151
+
152
+ ```css
153
+ .login-container {
154
+ /* Your custom styles */
155
+ }
156
+ ```
157
+
158
+ The form is responsive and will adapt to different screen sizes, with a maximum width of 400px.
159
+
160
+ ## Logout Component
161
+
162
+ The `LogoutComponent` provides a user-friendly confirmation dialog for logging out of the application. It ensures users don't accidentally log out by requiring explicit confirmation before signing out.
163
+
164
+ ### Features
165
+
166
+ - Clean, simple confirmation dialog with Material Design styling
167
+ - Asks for confirmation before logging out
168
+ - Shows loading state during the logout process
169
+ - Error handling for logout failures
170
+ - Automatic navigation back to the previous page after logout or cancellation
171
+
172
+ ### Usage
173
+
174
+ Add the component to your routes configuration:
175
+
176
+ ```typescript
177
+ const routes: Routes = [
178
+ { path: 'logout', component: LogoutComponent }
179
+ ];
180
+ ```
181
+
182
+ Then navigate to the logout route:
183
+
184
+ ```typescript
185
+ // In your component
186
+ constructor(private router: Router) {}
187
+
188
+ navigateToLogout() {
189
+ this.router.navigate(['/logout']);
190
+ }
191
+ ```
192
+
193
+ Or create a link in your template:
194
+
195
+ ```html
196
+ <a routerLink="/logout">Logout</a>
197
+ ```
198
+
199
+ The component is typically accessed through the `AuthButtonComponent` menu when a user is authenticated.
200
+
201
+ ### API Reference
202
+
203
+ #### Selector
204
+ `pp-logout`
205
+
206
+ #### Dependencies
207
+ - `AuthService` - Used for signing out the user
208
+ - `NavigateBackService` - Used for navigation after logout or cancellation
209
+ - Angular Material components (MatDialog, MatButton)
210
+
211
+ #### Properties
212
+ - `isLoading` - Signal that indicates whether a logout operation is in progress
213
+
214
+ #### Methods
215
+ - `onCancel()` - Handles cancellation of the logout process
216
+ - `onLogout()` - Handles the logout process, including error handling
217
+
218
+ ### Styling
219
+
220
+ The component uses Angular Material styling with custom CSS for layout. You can target the component with CSS using the `.logout-dialog` class:
221
+
222
+ ```css
223
+ .logout-dialog {
224
+ /* Your custom styles */
225
+ }
226
+ ```
227
+
228
+ The dialog is compact and focused, providing a clear confirmation message and action buttons.
229
+
230
+ ## Registration Component
231
+
232
+ The `RegistrationComponent` provides a user-friendly interface for creating a new account. It includes form validation, error handling, and visual feedback during the registration process.
233
+
234
+ ### Features
235
+
236
+ - Clean, responsive registration form with Material Design styling
237
+ - Email and password registration with Firebase
238
+ - Real-time form validation with error messages
239
+ - Password visibility toggle for both password fields
240
+ - Password confirmation with matching validation
241
+ - Password strength requirements (minimum 6 characters)
242
+ - Loading state indication during registration
243
+ - Error handling with user-friendly messages
244
+ - Automatic navigation back after successful registration
245
+ - Link to login page for users who already have an account
246
+
247
+ ### Usage
248
+
249
+ Add the component to your routes configuration:
250
+
251
+ ```typescript
252
+ const routes: Routes = [
253
+ { path: 'register', component: RegistrationComponent }
254
+ ];
255
+ ```
256
+
257
+ Then navigate to the registration route:
258
+
259
+ ```typescript
260
+ // In your component
261
+ constructor(private router: Router) {}
262
+
263
+ navigateToRegister() {
264
+ this.router.navigate(['/register']);
265
+ }
266
+ ```
267
+
268
+ Or create a link in your template:
269
+
270
+ ```html
271
+ <a routerLink="/register">Create Account</a>
272
+ ```
273
+
274
+ The component is typically accessed through the `AuthButtonComponent` menu when a user is not authenticated.
275
+
276
+ ### API Reference
277
+
278
+ #### Selector
279
+ `pp-registration`
280
+
281
+ #### Dependencies
282
+ - `Auth` from Firebase - Used for user registration
283
+ - `NavigateBackService` - Used for navigation after registration
284
+ - `MatSnackBar` - Used for displaying error messages
285
+ - Angular Material components (MatFormField, MatInput, MatButton, etc.)
286
+ - Angular Reactive Forms - For form handling and validation
287
+
288
+ #### Properties
289
+ - `registerForm` - FormGroup that manages the registration form state and validation
290
+ - `isLoading` - Signal that indicates whether a registration operation is in progress
291
+ - `errorMessage` - Signal that contains any error message to display
292
+ - `hidePassword` - Boolean that controls password visibility
293
+ - `hideConfirmPassword` - Boolean that controls confirm password visibility
294
+
295
+ #### Methods
296
+ - `onSubmit()` - Handles form submission for registration
297
+ - `getErrorMessage(errorCode: string)` - Converts Firebase error codes to user-friendly messages
298
+ - `passwordMatchValidator()` - Custom validator to ensure password and confirm password match
299
+
300
+ ### Styling
301
+
302
+ The component uses Angular Material styling with custom CSS for layout. You can target the component with CSS using the `.registration-container` class:
303
+
304
+ ```css
305
+ .registration-container {
306
+ /* Your custom styles */
307
+ }
308
+ ```
309
+
310
+ The form is responsive and will adapt to different screen sizes, with a maximum width of 400px.
311
+
312
+ ## My Profile Component
313
+
314
+ The `MyProfileComponent` provides a user interface for viewing and managing the authenticated user's profile information. It allows users to see their account details and potentially update their profile settings.
315
+
316
+ ### Features
317
+
318
+ - Accessible only to authenticated users
319
+ - Displays user profile information
320
+ - Clean, intuitive interface with Material Design styling
321
+ - Integrated with the authentication system
322
+
323
+ ### Usage
324
+
325
+ Add the component to your routes configuration:
326
+
327
+ ```typescript
328
+ const routes: Routes = [
329
+ { path: 'my-profile', component: MyProfileComponent }
330
+ ];
331
+ ```
332
+
333
+ Then navigate to the my-profile route:
334
+
335
+ ```typescript
336
+ // In your component
337
+ constructor(private router: Router) {}
338
+
339
+ navigateToProfile() {
340
+ this.router.navigate(['/my-profile']);
341
+ }
342
+ ```
343
+
344
+ Or create a link in your template:
345
+
346
+ ```html
347
+ <a routerLink="/my-profile">My Profile</a>
348
+ ```
349
+
350
+ The component is typically accessed through the `AuthButtonComponent` menu when a user is authenticated.
351
+
352
+ ### API Reference
353
+
354
+ #### Selector
355
+ `pp-my-profile`
356
+
357
+ #### Dependencies
358
+ - Angular Material components (for styling and UI elements)
359
+ - Authentication service (for accessing user profile data)
360
+
361
+ #### Properties
362
+ - Currently minimal implementation with planned expansion for user profile management
363
+
364
+ ### Styling
365
+
366
+ The component uses Angular Material styling with custom CSS for layout. You can target the component with CSS:
367
+
368
+ ```css
369
+ pp-my-profile {
370
+ /* Your custom styles */
371
+ }
372
+ ```
373
+
374
+ The profile view is designed to be clean and user-friendly, presenting user information in an organized manner.
375
+
376
+ ## Authentication Service
377
+
378
+ The `AuthService` provides core authentication functionality for the application, leveraging Firebase Authentication. It manages user authentication state and provides methods for common authentication operations.
379
+
380
+ ### Features
381
+
382
+ - Firebase Authentication integration
383
+ - Reactive authentication state management using Angular signals
384
+ - Simple API for checking authentication status
385
+ - Methods for signing out and retrieving the current user
386
+ - Singleton service available throughout the application
387
+
388
+ ### Usage
389
+
390
+ Import and inject the service in your components or other services:
391
+
392
+ ```typescript
393
+ import { Component, inject } from '@angular/core';
394
+ import { AuthService } from '@processpuzzle/auth';
395
+
396
+ @Component({
397
+ selector: 'app-example',
398
+ template: `
399
+ <div *ngIf="authService.isAuthenticated()">
400
+ Welcome, {{ authService.user()?.email }}!
401
+ <button (click)="logout()">Logout</button>
402
+ </div>
403
+ <div *ngIf="!authService.isAuthenticated()">
404
+ Please log in to continue.
405
+ </div>
406
+ `
407
+ })
408
+ export class ExampleComponent {
409
+ authService = inject(AuthService);
410
+
411
+ async logout() {
412
+ await this.authService.signOut();
413
+ // Handle post-logout navigation or UI updates
414
+ }
415
+ }
416
+ ```
417
+
418
+ ### API Reference
419
+
420
+ #### Dependencies
421
+ - `Auth` from Firebase - Used for authentication operations
422
+ - Angular's dependency injection system
423
+
424
+ #### Properties
425
+ - `user` - A signal that provides the current Firebase User object or null if not authenticated
426
+ - `isAuthenticated` - A computed signal that returns true if a user is logged in, false otherwise
427
+
428
+ #### Methods
429
+ - `signOut()` - Asynchronous method that signs out the current user
430
+ - `getCurrentUser()` - Synchronous method that returns the current Firebase User object or null
431
+
432
+ ### Integration with Components
433
+
434
+ The `AuthService` is used by several components in the auth library:
435
+
436
+ - `AuthButtonComponent` uses it to determine which menu options to display
437
+ - `LogoutComponent` uses it to sign out the user
438
+ - `AuthGuard` uses it to protect routes that require authentication
439
+
440
+ ## Authentication Guard
441
+
442
+ The `authGuard` is a route guard that protects routes requiring authentication. It redirects unauthenticated users to the login page when they attempt to access protected routes.
443
+
444
+ ### Features
445
+
446
+ - Functional route guard using Angular's dependency injection
447
+ - Integrates with the `AuthService` to check authentication status
448
+ - Redirects unauthenticated users to the login page
449
+ - Simple API that works with Angular Router
450
+
451
+ ### Usage
452
+
453
+ Add the guard to your routes configuration:
454
+
455
+ ```typescript
456
+ import { Routes } from '@angular/router';
457
+ import { authGuard } from '@processpuzzle/auth';
458
+
459
+ export const routes: Routes = [
460
+ {
461
+ path: 'protected',
462
+ component: ProtectedComponent,
463
+ canActivate: [authGuard]
464
+ }
465
+ ];
466
+ ```
467
+
468
+ ### API Reference
469
+
470
+ #### Dependencies
471
+ - `Router` from Angular - Used for navigation to the login page
472
+ - `AuthService` - Used to check authentication status
473
+
474
+ #### Behavior
475
+ - Returns `true` if the user is authenticated, allowing navigation to the protected route
476
+ - Redirects to '/auth/login' and returns `false` if the user is not authenticated, preventing navigation to the protected route
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@processpuzzle/auth",
3
+ "version": "0.0.1",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ZsZs/processpuzzle.git",
10
+ "directory": "libs/auth"
11
+ },
12
+ "homepage": "https://github.com/ZsZs/processpuzzle#readme",
13
+ "peerDependencies": {
14
+ "@angular/common": "^19.2.0",
15
+ "@angular/core": "^19.2.0"
16
+ },
17
+ "exports": {
18
+ "./i18n/*": "./i18n/pp-auth/*",
19
+ "./package.json": {
20
+ "default": "./package.json"
21
+ },
22
+ ".": {
23
+ "types": "./index.d.ts",
24
+ "default": "./fesm2022/processpuzzle-auth.mjs"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist/libs/auth/",
29
+ "i18n/"
30
+ ],
31
+ "sideEffects": false,
32
+ "module": "fesm2022/processpuzzle-auth.mjs",
33
+ "typings": "index.d.ts",
34
+ "dependencies": {
35
+ "tslib": "^2.3.0"
36
+ }
37
+ }