@@ -94,7 +94,9 @@ export class AuthenticationService {
94
94
*/
95
95
login ( loginContext : LoginContext ) {
96
96
this . alertService . alert ( { type : 'Authentication Start' , message : 'Please wait...' } ) ;
97
- this . rememberMe = loginContext . remember ;
97
+ // Only allow Remember Me if enabled in config
98
+ const rememberAllowed = environment . enableRememberMe === true ;
99
+ this . rememberMe = rememberAllowed ? loginContext . remember : false ;
98
100
this . storage = this . rememberMe ? localStorage : sessionStorage ;
99
101
100
102
if ( environment . oauth . enabled ) {
@@ -103,6 +105,7 @@ export class AuthenticationService {
103
105
httpParams = httpParams . set ( 'password' , loginContext . password ) ;
104
106
httpParams = httpParams . set ( 'client_id' , `${ environment . oauth . appId } ` ) ;
105
107
httpParams = httpParams . set ( 'grant_type' , 'password' ) ;
108
+ httpParams = httpParams . set ( 'remember_me' , this . rememberMe ? 'true' : 'false' ) ;
106
109
let headers = new HttpHeaders ( ) ;
107
110
headers = headers . set ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
108
111
return this . http . post ( `${ environment . oauth . serverUrl } /token` , httpParams . toString ( ) , { headers : headers } ) . pipe (
@@ -113,7 +116,11 @@ export class AuthenticationService {
113
116
) ;
114
117
} else {
115
118
return this . http
116
- . post ( '/authentication' , { username : loginContext . username , password : loginContext . password } )
119
+ . post ( '/authentication' , {
120
+ username : loginContext . username ,
121
+ password : loginContext . password ,
122
+ remember : this . rememberMe
123
+ } )
117
124
. pipe (
118
125
map ( ( credentials : Credentials ) => {
119
126
this . onLoginSuccess ( credentials ) ;
@@ -193,6 +200,9 @@ export class AuthenticationService {
193
200
*/
194
201
private onLoginSuccess ( credentials : Credentials ) {
195
202
this . userLoggedIn = true ;
203
+ // Ensure the rememberMe value is preserved in credentials
204
+ credentials . rememberMe = this . rememberMe ;
205
+
196
206
if ( environment . oauth . enabled ) {
197
207
this . authenticationInterceptor . setAuthorizationToken ( credentials . accessToken ) ;
198
208
} else {
@@ -304,11 +314,17 @@ export class AuthenticationService {
304
314
private setCredentials ( credentials ?: Credentials ) {
305
315
if ( credentials ) {
306
316
credentials . rememberMe = this . rememberMe ;
317
+ // Make sure we're using the correct storage based on rememberMe value
318
+ this . storage = credentials . rememberMe ? localStorage : sessionStorage ;
307
319
this . storage . setItem ( this . credentialsStorageKey , JSON . stringify ( credentials ) ) ;
308
320
} else {
309
- this . storage . removeItem ( this . credentialsStorageKey ) ;
310
- this . storage . removeItem ( this . oAuthTokenDetailsStorageKey ) ;
311
- this . storage . removeItem ( this . twoFactorAuthenticationTokenStorageKey ) ;
321
+ // Clear credentials from both storage types to ensure complete logout
322
+ localStorage . removeItem ( this . credentialsStorageKey ) ;
323
+ sessionStorage . removeItem ( this . credentialsStorageKey ) ;
324
+ localStorage . removeItem ( this . oAuthTokenDetailsStorageKey ) ;
325
+ sessionStorage . removeItem ( this . oAuthTokenDetailsStorageKey ) ;
326
+ localStorage . removeItem ( this . twoFactorAuthenticationTokenStorageKey ) ;
327
+ sessionStorage . removeItem ( this . twoFactorAuthenticationTokenStorageKey ) ;
312
328
}
313
329
}
314
330
0 commit comments