Skip to content

Commit 4940cd7

Browse files
authored
Merge pull request #2653 from JaySoni1/WEB-194-remember-me-on-login-page-doesnt-do-what-its-supposed-to
WEB-194 Remember Me on Login page doesn't do what it's supposed to
2 parents a3f3eb5 + 1c86e31 commit 4940cd7

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

src/app/core/authentication/authentication.service.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export class AuthenticationService {
9494
*/
9595
login(loginContext: LoginContext) {
9696
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;
98100
this.storage = this.rememberMe ? localStorage : sessionStorage;
99101

100102
if (environment.oauth.enabled) {
@@ -103,6 +105,7 @@ export class AuthenticationService {
103105
httpParams = httpParams.set('password', loginContext.password);
104106
httpParams = httpParams.set('client_id', `${environment.oauth.appId}`);
105107
httpParams = httpParams.set('grant_type', 'password');
108+
httpParams = httpParams.set('remember_me', this.rememberMe ? 'true' : 'false');
106109
let headers = new HttpHeaders();
107110
headers = headers.set('Content-Type', 'application/x-www-form-urlencoded');
108111
return this.http.post(`${environment.oauth.serverUrl}/token`, httpParams.toString(), { headers: headers }).pipe(
@@ -113,7 +116,11 @@ export class AuthenticationService {
113116
);
114117
} else {
115118
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+
})
117124
.pipe(
118125
map((credentials: Credentials) => {
119126
this.onLoginSuccess(credentials);
@@ -193,6 +200,9 @@ export class AuthenticationService {
193200
*/
194201
private onLoginSuccess(credentials: Credentials) {
195202
this.userLoggedIn = true;
203+
// Ensure the rememberMe value is preserved in credentials
204+
credentials.rememberMe = this.rememberMe;
205+
196206
if (environment.oauth.enabled) {
197207
this.authenticationInterceptor.setAuthorizationToken(credentials.accessToken);
198208
} else {
@@ -304,11 +314,17 @@ export class AuthenticationService {
304314
private setCredentials(credentials?: Credentials) {
305315
if (credentials) {
306316
credentials.rememberMe = this.rememberMe;
317+
// Make sure we're using the correct storage based on rememberMe value
318+
this.storage = credentials.rememberMe ? localStorage : sessionStorage;
307319
this.storage.setItem(this.credentialsStorageKey, JSON.stringify(credentials));
308320
} 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);
312328
}
313329
}
314330

src/app/login/login-form/login-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</mat-error>
3434
</mat-form-field>
3535

36-
<mat-checkbox formControlName="remember" class="m-t-10 flex-align-center">{{
36+
<mat-checkbox *ngIf="enableRememberMe" formControlName="remember" class="m-t-10 flex-align-center">{{
3737
'labels.inputs.Remember me' | translate
3838
}}</mat-checkbox>
3939

src/app/login/login-form/login-form.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export class LoginFormComponent implements OnInit {
4444
/** True if loading. */
4545
loading = false;
4646
oidcServerEnabled = environment.OIDC.oidcServerEnabled;
47+
/** Whether remember me functionality is enabled */
48+
enableRememberMe = environment.enableRememberMe === true;
4749

4850
/**
4951
* @param {FormBuilder} formBuilder Form Builder.

src/environments/environment.prod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export const environment = {
2929
serverUrl: loadedEnv['oauthServerUrl'] || '',
3030
appId: loadedEnv['oauthAppId'] || ''
3131
},
32+
/** Feature flag for Remember Me functionality */
33+
enableRememberMe: false,
3234
warningDialog: {
3335
title: 'Warning',
3436
content:

src/environments/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const environment = {
2828
apiProvider: loadedEnv.apiProvider || '/fineract-provider/api',
2929
apiVersion: loadedEnv.apiVersion || '/v1',
3030
serverUrl: '',
31+
/** Feature flag for Remember Me functionality */
32+
enableRememberMe: false,
3133
oauth: {
3234
enabled: loadedEnv.oauthServerEnabled || false, // For connecting to Mifos X using OAuth2 Authentication change the value to true
3335
serverUrl: loadedEnv.oauthServerUrl || '',

0 commit comments

Comments
 (0)