@acontplus/ng-auth 1.0.2 → 1.1.0

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/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { ITokenProvider } from '@acontplus/ng-infrastructure';
1
+ import { ITokenProvider, BaseUseCase } from '@acontplus/ng-infrastructure';
2
2
  export { ITokenProvider, TOKEN_PROVIDER } from '@acontplus/ng-infrastructure';
3
3
  import { CanActivateFn } from '@angular/router';
4
4
  import { AuthTokens, BaseEntity, UserData } from '@acontplus/core';
5
5
  import * as i0 from '@angular/core';
6
6
  import { OnDestroy, OnInit, TemplateRef, Provider } from '@angular/core';
7
+ import { HttpInterceptorFn } from '@angular/common/http';
7
8
  import { Observable } from 'rxjs';
8
9
  import { AbstractControl, FormGroup } from '@angular/forms';
9
10
 
@@ -16,11 +17,15 @@ declare class TokenRepository {
16
17
  getAccessToken(): string | null;
17
18
  getRefreshToken(): string | null;
18
19
  setToken(token: string, rememberMe?: boolean): void;
19
- setRefreshToken(_refreshToken: string, _rememberMe?: boolean): void;
20
+ setRefreshToken(refreshToken: string, rememberMe?: boolean): void;
20
21
  clearTokens(): void;
21
22
  isAuthenticated(): boolean;
22
23
  needsRefresh(): boolean;
23
24
  getTokenPayload(): any;
25
+ /**
26
+ * Determines if tokens are stored persistently (localStorage) vs session (sessionStorage)
27
+ */
28
+ isRememberMeEnabled(): boolean;
24
29
  static ɵfac: i0.ɵɵFactoryDeclaration<TokenRepository, never>;
25
30
  static ɵprov: i0.ɵɵInjectableDeclaration<TokenRepository>;
26
31
  }
@@ -34,25 +39,71 @@ declare class AuthTokenService implements ITokenProvider {
34
39
  static ɵprov: i0.ɵɵInjectableDeclaration<AuthTokenService>;
35
40
  }
36
41
 
37
- declare class CsrfService {
38
- private http;
39
- private environment;
40
- private csrfToken;
42
+ /**
43
+ * Service to manage URL redirection after authentication
44
+ * Stores the intended URL when session is lost and redirects to it after successful login
45
+ * SSR-compatible by checking platform before accessing sessionStorage
46
+ */
47
+ declare class UrlRedirectService {
48
+ private readonly REDIRECT_URL_KEY;
49
+ private readonly EXCLUDED_ROUTES;
50
+ private readonly router;
51
+ private readonly platformId;
52
+ private readonly document;
53
+ /**
54
+ * Stores the current URL for later redirection
55
+ * @param url - The URL to store (defaults to current URL)
56
+ */
57
+ storeIntendedUrl(url?: string): void;
41
58
  /**
42
- * Get CSRF token, fetching it if not available
59
+ * Gets the stored intended URL
60
+ * @returns The stored URL or null if none exists
43
61
  */
44
- getCsrfToken(): Promise<string>;
62
+ getIntendedUrl(): string | null;
45
63
  /**
46
- * Clear stored CSRF token (useful on logout)
64
+ * Redirects to the stored URL and clears it from storage
65
+ * @param defaultRoute - The default route to navigate to if no URL is stored
47
66
  */
48
- clearCsrfToken(): void;
49
- static ɵfac: i0.ɵɵFactoryDeclaration<CsrfService, never>;
50
- static ɵprov: i0.ɵɵInjectableDeclaration<CsrfService>;
67
+ redirectToIntendedUrl(defaultRoute?: string): void;
68
+ /**
69
+ * Clears the stored intended URL
70
+ */
71
+ clearIntendedUrl(): void;
72
+ /**
73
+ * Checks if a URL should be excluded from redirection
74
+ * @param url - The URL to check
75
+ * @returns True if the URL should be excluded
76
+ */
77
+ private isExcludedRoute;
78
+ /**
79
+ * Stores the current URL if it's not an excluded route
80
+ * Useful for guards and interceptors
81
+ */
82
+ storeCurrentUrlIfAllowed(): void;
83
+ /**
84
+ * Checks if we're running in a browser environment
85
+ * @returns True if running in browser, false if SSR
86
+ */
87
+ private isBrowser;
88
+ /**
89
+ * Safely gets sessionStorage reference
90
+ * @returns sessionStorage object or null if not available
91
+ */
92
+ private getSessionStorage;
93
+ static ɵfac: i0.ɵɵFactoryDeclaration<UrlRedirectService, never>;
94
+ static ɵprov: i0.ɵɵInjectableDeclaration<UrlRedirectService>;
51
95
  }
52
96
 
97
+ /**
98
+ * Interceptor that handles authentication errors and manages URL redirection
99
+ * Captures the current URL when a 401 error occurs and redirects to login
100
+ */
101
+ declare const authRedirectInterceptor: HttpInterceptorFn;
102
+
53
103
  interface LoginRequest {
54
104
  email: string;
55
105
  password: string;
106
+ rememberMe?: boolean;
56
107
  }
57
108
  interface RegisterRequest {
58
109
  email: string;
@@ -64,9 +115,8 @@ interface RefreshTokenRequest {
64
115
  refreshToken: string;
65
116
  }
66
117
  interface RegisterResponse {
67
- id: string;
68
- email: string;
69
- displayName: string;
118
+ token: string;
119
+ refreshToken: string;
70
120
  }
71
121
  declare class User implements BaseEntity {
72
122
  readonly id: number;
@@ -82,7 +132,7 @@ declare class User implements BaseEntity {
82
132
 
83
133
  declare abstract class AuthRepository {
84
134
  abstract login(request: LoginRequest): Observable<AuthTokens>;
85
- abstract register(request: RegisterRequest): Observable<User>;
135
+ abstract register(request: RegisterRequest): Observable<AuthTokens>;
86
136
  abstract refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
87
137
  abstract logout(email: string, refreshToken: string): Observable<void>;
88
138
  }
@@ -92,31 +142,33 @@ declare class AuthHttpRepository extends AuthRepository {
92
142
  private readonly csrfService;
93
143
  private readonly URL;
94
144
  login(request: LoginRequest): Observable<AuthTokens>;
95
- register(request: RegisterRequest): Observable<User>;
145
+ register(request: RegisterRequest): Observable<AuthTokens>;
96
146
  refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
97
147
  logout(email: string, refreshToken: string): Observable<void>;
98
148
  static ɵfac: i0.ɵɵFactoryDeclaration<AuthHttpRepository, never>;
99
149
  static ɵprov: i0.ɵɵInjectableDeclaration<AuthHttpRepository>;
100
150
  }
101
151
 
102
- declare class LoginUseCase {
152
+ declare class LoginUseCase extends BaseUseCase<LoginRequest, AuthTokens> {
103
153
  private readonly authRepository;
104
154
  private readonly authStore;
105
155
  private readonly router;
156
+ private readonly urlRedirectService;
106
157
  execute(request: LoginRequest): Observable<AuthTokens>;
107
158
  static ɵfac: i0.ɵɵFactoryDeclaration<LoginUseCase, never>;
108
159
  static ɵprov: i0.ɵɵInjectableDeclaration<LoginUseCase>;
109
160
  }
110
161
 
111
- declare class RegisterUseCase {
162
+ declare class RegisterUseCase extends BaseUseCase<RegisterRequest, AuthTokens> {
112
163
  private readonly authRepository;
164
+ private readonly authStore;
113
165
  private readonly router;
114
- execute(request: RegisterRequest): Observable<User>;
166
+ execute(request: RegisterRequest): Observable<AuthTokens>;
115
167
  static ɵfac: i0.ɵɵFactoryDeclaration<RegisterUseCase, never>;
116
168
  static ɵprov: i0.ɵɵInjectableDeclaration<RegisterUseCase>;
117
169
  }
118
170
 
119
- declare class RefreshTokenUseCase {
171
+ declare class RefreshTokenUseCase extends BaseUseCase<void, AuthTokens> {
120
172
  private readonly authRepository;
121
173
  private readonly userRepository;
122
174
  private readonly tokenRepository;
@@ -126,7 +178,7 @@ declare class RefreshTokenUseCase {
126
178
  static ɵprov: i0.ɵɵInjectableDeclaration<RefreshTokenUseCase>;
127
179
  }
128
180
 
129
- declare class LogoutUseCase {
181
+ declare class LogoutUseCase extends BaseUseCase<void, void> {
130
182
  private readonly authRepository;
131
183
  private readonly userRepository;
132
184
  private readonly tokenRepository;
@@ -170,7 +222,7 @@ declare class AuthStore implements OnDestroy {
170
222
  /**
171
223
  * Set authentication state after successful login
172
224
  */
173
- setAuthenticated(tokens: AuthTokens): void;
225
+ setAuthenticated(tokens: AuthTokens, rememberMe?: boolean): void;
174
226
  /**
175
227
  * Logout user and clear all authentication data
176
228
  */
@@ -198,6 +250,7 @@ declare class AuthStore implements OnDestroy {
198
250
  declare class LoginComponent implements OnInit {
199
251
  title: i0.InputSignal<string>;
200
252
  showRegisterButton: i0.InputSignal<boolean>;
253
+ showRememberMe: i0.InputSignal<boolean>;
201
254
  additionalSigninControls: i0.InputSignal<Record<string, AbstractControl<any, any, any>>>;
202
255
  additionalSignupControls: i0.InputSignal<Record<string, AbstractControl<any, any, any>>>;
203
256
  additionalSigninFields: i0.InputSignal<TemplateRef<any> | null>;
@@ -218,10 +271,10 @@ declare class LoginComponent implements OnInit {
218
271
  signIn(): void;
219
272
  registerUser(): void;
220
273
  static ɵfac: i0.ɵɵFactoryDeclaration<LoginComponent, never>;
221
- static ɵcmp: i0.ɵɵComponentDeclaration<LoginComponent, "acp-login", never, { "title": { "alias": "title"; "required": false; "isSignal": true; }; "showRegisterButton": { "alias": "showRegisterButton"; "required": false; "isSignal": true; }; "additionalSigninControls": { "alias": "additionalSigninControls"; "required": false; "isSignal": true; }; "additionalSignupControls": { "alias": "additionalSignupControls"; "required": false; "isSignal": true; }; "additionalSigninFields": { "alias": "additionalSigninFields"; "required": false; "isSignal": true; }; "additionalSignupFields": { "alias": "additionalSignupFields"; "required": false; "isSignal": true; }; "footerContent": { "alias": "footerContent"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
274
+ static ɵcmp: i0.ɵɵComponentDeclaration<LoginComponent, "acp-login", never, { "title": { "alias": "title"; "required": false; "isSignal": true; }; "showRegisterButton": { "alias": "showRegisterButton"; "required": false; "isSignal": true; }; "showRememberMe": { "alias": "showRememberMe"; "required": false; "isSignal": true; }; "additionalSigninControls": { "alias": "additionalSigninControls"; "required": false; "isSignal": true; }; "additionalSignupControls": { "alias": "additionalSignupControls"; "required": false; "isSignal": true; }; "additionalSigninFields": { "alias": "additionalSigninFields"; "required": false; "isSignal": true; }; "additionalSignupFields": { "alias": "additionalSignupFields"; "required": false; "isSignal": true; }; "footerContent": { "alias": "footerContent"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
222
275
  }
223
276
 
224
277
  declare const authProviders: Provider[];
225
278
 
226
- export { AuthHttpRepository, AuthRepository, AuthStore, AuthTokenService, CsrfService, LoginComponent, LoginUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUseCase, TokenRepository, User, authGuard, authProviders };
279
+ export { AuthHttpRepository, AuthRepository, AuthStore, AuthTokenService, LoginComponent, LoginUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUseCase, TokenRepository, UrlRedirectService, User, authGuard, authProviders, authRedirectInterceptor };
227
280
  export type { LoginRequest, RefreshTokenRequest, RegisterRequest, RegisterResponse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontplus/ng-auth",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Acontplus Angular Authentication Module",
5
5
  "dependencies": {
6
6
  "@acontplus/ng-infrastructure": "^1.0.1",