Skip to content

Commit

Permalink
Show error on login screen if rune is incorrect and getinfo throws er…
Browse files Browse the repository at this point in the history
…ror (#1391)
  • Loading branch information
ShahanaFarooqui authored May 13, 2024
1 parent a96422f commit e75cc2d
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 71 deletions.
18 changes: 5 additions & 13 deletions backend/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,7 @@ export class CommonService {
}
};
this.handleError = (errRes, fileName, errMsg, selectedNode) => {
let err = JSON.parse(JSON.stringify(errRes));
if (err && err.error && Object.keys(err.error).length === 0 && errRes.error && (errRes.error.stack || errRes.error.message)) {
errRes.error = errRes.error.stack || errRes.error.message;
err = JSON.parse(JSON.stringify(errRes));
}
else if (errRes.message || errRes.stack) {
errRes.error = errRes.message || errRes.stack;
err = JSON.parse(JSON.stringify(errRes));
}
const err = JSON.parse(JSON.stringify(errRes));
if (!selectedNode) {
selectedNode = this.selectedNode;
}
Expand All @@ -325,11 +317,11 @@ export class CommonService {
}
break;
case 'CLN':
if (err.options && err.options.headers && err.options.headers.macaroon) {
delete err.options.headers.macaroon;
if (err.options && err.options.headers && err.options.headers.rune) {
delete err.options.headers.rune;
}
if (err.response && err.response.request && err.response.request.headers && err.response.request.headers.macaroon) {
delete err.response.request.headers.macaroon;
if (err.response && err.response.request && err.response.request.headers && err.response.request.headers.rune) {
delete err.response.request.headers.rune;
}
break;
case 'ECL':
Expand Down
5 changes: 3 additions & 2 deletions backend/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ export class ConfigService {
fs.writeFileSync(confFileFullPath, JSON.stringify(config, null, 2), 'utf-8');
};
this.setServerConfiguration = () => {
const rtlConfFilePath = (process?.env?.RTL_CONFIG_PATH) ? process?.env?.RTL_CONFIG_PATH : join(this.directoryName, '../..');
const confFileFullPath = rtlConfFilePath + sep + 'RTL-Config.json';
try {
const rtlConfFilePath = (process?.env?.RTL_CONFIG_PATH) ? process?.env?.RTL_CONFIG_PATH : join(this.directoryName, '../..');
const confFileFullPath = rtlConfFilePath + sep + 'RTL-Config.json';
if (!fs.existsSync(confFileFullPath)) {
fs.writeFileSync(confFileFullPath, JSON.stringify(this.setDefaultConfig(), null, 2), 'utf-8');
}
Expand All @@ -390,6 +390,7 @@ export class ConfigService {
this.common.appConfig = config;
}
catch (err) {
this.logger.log({ selectedNode: this.common.selectedNode, level: 'ERROR', fileName: 'Config', msg: 'Config file path: ' + confFileFullPath });
this.logger.log({ selectedNode: this.common.selectedNode, level: 'ERROR', fileName: 'Config', msg: 'Something went wrong while configuring the node server: \n' + err });
throw new Error(err);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion frontend/main.5525c82b788903bc.js

This file was deleted.

1 change: 1 addition & 0 deletions frontend/main.d750cc46804fb3a1.js

Large diffs are not rendered by default.

17 changes: 5 additions & 12 deletions server/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,7 @@ export class CommonService {
};

public handleError = (errRes, fileName, errMsg, selectedNode: SelectedNode) => {
let err = JSON.parse(JSON.stringify(errRes));
if (err && err.error && Object.keys(err.error).length === 0 && errRes.error && (errRes.error.stack || errRes.error.message)) {
errRes.error = errRes.error.stack || errRes.error.message;
err = JSON.parse(JSON.stringify(errRes));
} else if (errRes.message || errRes.stack) {
errRes.error = errRes.message || errRes.stack;
err = JSON.parse(JSON.stringify(errRes));
}
const err = JSON.parse(JSON.stringify(errRes));
if (!selectedNode) { selectedNode = this.selectedNode; }
switch (selectedNode.lnImplementation) {
case 'LND':
Expand All @@ -343,11 +336,11 @@ export class CommonService {
break;

case 'CLN':
if (err.options && err.options.headers && err.options.headers.macaroon) {
delete err.options.headers.macaroon;
if (err.options && err.options.headers && err.options.headers.rune) {
delete err.options.headers.rune;
}
if (err.response && err.response.request && err.response.request.headers && err.response.request.headers.macaroon) {
delete err.response.request.headers.macaroon;
if (err.response && err.response.request && err.response.request.headers && err.response.request.headers.rune) {
delete err.response.request.headers.rune;
}
break;

Expand Down
5 changes: 3 additions & 2 deletions server/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ export class ConfigService {
};

public setServerConfiguration = () => {
const rtlConfFilePath = (process?.env?.RTL_CONFIG_PATH) ? process?.env?.RTL_CONFIG_PATH : join(this.directoryName, '../..');
const confFileFullPath = rtlConfFilePath + sep + 'RTL-Config.json';
try {
const rtlConfFilePath = (process?.env?.RTL_CONFIG_PATH) ? process?.env?.RTL_CONFIG_PATH : join(this.directoryName, '../..');
const confFileFullPath = rtlConfFilePath + sep + 'RTL-Config.json';
if (!fs.existsSync(confFileFullPath)) {
fs.writeFileSync(confFileFullPath, JSON.stringify(this.setDefaultConfig(), null, 2), 'utf-8');
}
Expand All @@ -367,6 +367,7 @@ export class ConfigService {
this.setSelectedNode(config);
this.common.appConfig = config;
} catch (err: any) {
this.logger.log({ selectedNode: this.common.selectedNode, level: 'ERROR', fileName: 'Config', msg: 'Config file path: ' + confFileFullPath });
this.logger.log({ selectedNode: this.common.selectedNode, level: 'ERROR', fileName: 'Config', msg: 'Something went wrong while configuring the node server: \n' + err });
throw new Error(err);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
this.store.dispatch(login({ payload: { password: sha256(this.accessKey).toString(), defaultPassword: false } }));
}
} else {
this.router.navigate(['./login']);
this.router.navigate(['./login'], { state: { logoutReason: 'Access key too short. It should be at least 32 characters long.' } });
}
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
}
}
}));
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: 'Logging Out. Time limit exceeded for session inactivity.' }));
}
});
if (this.sessionService.getItem('defaultPassword') === 'true') {
Expand Down
12 changes: 6 additions & 6 deletions src/app/cln/store/cln.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class CLNEffects implements OnDestroy {
}));
}, 500);
return {
type: RTLActions.LOGOUT
type: RTLActions.LOGOUT,
payload: 'Sorry Not Sorry, RTL is Bitcoin Only!'
};
} else {
this.initializeRemainingData(info, action.payload.loadPage);
Expand All @@ -114,7 +115,7 @@ export class CLNEffects implements OnDestroy {
catchError((err) => {
const code = this.commonService.extractErrorCode(err);
const msg = (code === 'ETIMEDOUT') ? 'Unable to Connect to Core Lightning Server.' : this.commonService.extractErrorMessage(err);
this.router.navigate(['/error'], { state: { errorCode: code, errorMessage: msg } });
this.router.navigate(['/login'], { state: { logoutReason: JSON.stringify(msg) } });
this.handleErrorWithoutAlert('FetchInfo', UI_MESSAGES.GET_NODE_INFO, 'Fetching Node Info Failed.', { status: code, error: msg });
return of({ type: RTLActions.VOID });
})
Expand Down Expand Up @@ -926,8 +927,7 @@ export class CLNEffects implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
const errMsg = this.commonService.extractErrorMessage(err, genericErrorMessage);
Expand All @@ -940,8 +940,8 @@ export class CLNEffects implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed: ' + err.error }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
const errMsg = this.commonService.extractErrorMessage(err);
Expand Down
6 changes: 2 additions & 4 deletions src/app/eclair/store/ecl.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,7 @@ export class ECLEffects implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
this.store.dispatch(updateECLAPICallStatus({ payload: { action: actionName, status: APICallStatusEnum.ERROR, statusCode: err.status.toString(), message: this.commonService.extractErrorMessage(err, genericErrorMessage) } }));
Expand All @@ -800,8 +799,7 @@ export class ECLEffects implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
const errMsg = this.commonService.extractErrorMessage(err);
Expand Down
6 changes: 2 additions & 4 deletions src/app/lnd/store/lnd.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,7 @@ export class LNDEffects implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
this.store.dispatch(updateLNDAPICallStatus({ payload: { action: actionName, status: APICallStatusEnum.ERROR, statusCode: err.status.toString(), message: this.commonService.extractErrorMessage(err, genericErrorMessage) } }));
Expand All @@ -1308,8 +1307,7 @@ export class LNDEffects implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
const errMsg = this.commonService.extractErrorMessage(err);
Expand Down
8 changes: 6 additions & 2 deletions src/app/shared/components/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
</button>
<mat-error *ngIf="!password">Password is required.</mat-error>
</mat-form-field>
<p *ngIf="loginErrorMessage !== ''" fxFlex="100" class="color-warn pre-wrap" fxLayoutAlign="start start">
<mat-icon class="mr-1 icon-small">close</mat-icon>
<p *ngIf="loginErrorMessage !== ''" class="color-warn pre-wrap" fxFlex="100" fxLayoutAlign="start center">
<mat-icon class="mr-3px icon-small" fxLayoutAlign="center center">close</mat-icon>
{{loginErrorMessage}}
</p>
<p *ngIf="logoutReason !== ''" class="color-warn pre-wrap" fxLayout="row" fxFlex="100" fxLayoutAlign="start center">
<mat-icon class="mr-3px icon-small" fxLayoutAlign="center center">close</mat-icon>
{{logoutReason}}
</p>
<div fxLayout="row" fxFlex="100" fxLayoutAlign="end center" class="mt-2">
<button class="mr-1 mb-2" mat-stroked-button color="primary" tabindex="2" type="reset" (click)="resetData()">Clear</button>
<button mat-flat-button color="primary" tabindex="3" type="submit" (click)="onLogin()">Login</button>
Expand Down
14 changes: 11 additions & 3 deletions src/app/shared/components/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject, combineLatest } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { filter, take, takeUntil } from 'rxjs/operators';
import * as sha256 from 'sha256';
import { Store } from '@ngrx/store';
import { Actions } from '@ngrx/effects';
import { faUnlockAlt } from '@fortawesome/free-solid-svg-icons';

import { LoginTokenComponent } from '../data-modal/login-2fa-token/login-2fa-token.component';
import { RTLConfiguration } from '../../models/RTLconfig';
import { APICallStatusEnum, PASSWORD_BLACKLIST, ScreenSizeEnum } from '../../services/consts-enums-functions';
import { APICallStatusEnum, PASSWORD_BLACKLIST, RTLActions, ScreenSizeEnum } from '../../services/consts-enums-functions';
import { CommonService } from '../../services/common.service';
import { LoggerService } from '../../services/logger.service';

Expand All @@ -25,6 +26,7 @@ export class LoginComponent implements OnInit, OnDestroy {

public faUnlockAlt = faUnlockAlt;
public appConfig: RTLConfiguration;
public logoutReason = '';
public password = '';
public rtlSSO = 0;
public rtlCookiePath = '';
Expand All @@ -36,7 +38,7 @@ export class LoginComponent implements OnInit, OnDestroy {
public apiCallStatusEnum = APICallStatusEnum;
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject()];

constructor(private logger: LoggerService, private store: Store<RTLState>, private rtlEffects: RTLEffects, private commonService: CommonService) { }
constructor(private actions: Actions, private logger: LoggerService, private store: Store<RTLState>, private rtlEffects: RTLEffects, private commonService: CommonService) { }

ngOnInit() {
this.screenSize = this.commonService.getScreenSize();
Expand All @@ -56,13 +58,18 @@ export class LoginComponent implements OnInit, OnDestroy {
this.appConfig = appConfig;
this.logger.info(appConfig);
});
this.actions.pipe(filter((action) => action.type === RTLActions.LOGOUT), take(1)).
subscribe((action: any) => {
this.logoutReason = action.payload;
});
}

onLogin(): boolean | void {
if (!this.password) {
return true;
}
this.loginErrorMessage = '';
this.logoutReason = '';
if (this.appConfig.enable2FA) {
this.store.dispatch(openAlert({
payload: {
Expand All @@ -87,6 +94,7 @@ export class LoginComponent implements OnInit, OnDestroy {
resetData() {
this.password = '';
this.loginErrorMessage = '';
this.logoutReason = '';
this.flgShow = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class SideNavigationComponent implements OnInit, OnDestroy {
subscribe((confirmRes) => {
if (confirmRes) {
this.showLogout = false;
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: '' }));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TopMenuComponent implements OnInit, OnDestroy {
subscribe((confirmRes) => {
if (confirmRes) {
this.showLogout = false;
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: '' }));
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/services/boltz.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class BoltzService implements OnDestroy {
if (err.status === 401) {
errMsg = 'Unauthorized User.';
this.logger.info('Redirecting to Login');
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: errMsg }));
} else if (err.status === 503) {
errMsg = 'Unable to Connect to Boltz Server.';
this.store.dispatch(openAlert({
Expand All @@ -121,14 +121,14 @@ export class BoltzService implements OnDestroy {
let errMsg = '';
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
}
this.logger.error(err);
this.store.dispatch(closeSpinner({ payload: uiMessage }));
if (err.status === 401) {
errMsg = 'Unauthorized User.';
this.logger.info('Redirecting to Login');
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: errMsg }));
} else if (err.status === 503) {
errMsg = 'Unable to Connect to Boltz Server.';
setTimeout(() => {
Expand Down
6 changes: 2 additions & 4 deletions src/app/shared/services/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ export class DataService implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: actionName, status: APICallStatusEnum.ERROR, statusCode: err.status.toString(), message: this.extractErrorMessage(err) } }));
Expand All @@ -431,8 +430,7 @@ export class DataService implements OnDestroy {
if (err.status === 401) {
this.logger.info('Redirecting to Login');
this.store.dispatch(closeAllDialogs());
this.store.dispatch(logout());
this.store.dispatch(openSnackBar({ payload: 'Authentication Failed. Redirecting to Login.' }));
this.store.dispatch(logout({ payload: 'Authentication Failed: ' + JSON.stringify(err.error) }));
} else {
this.store.dispatch(closeSpinner({ payload: uiMessage }));
const errMsg = this.extractErrorMessage(err);
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/services/loop.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class LoopService implements OnDestroy {
if (err.status === 401) {
errMsg = 'Unauthorized User.';
this.logger.info('Redirecting to Login');
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: errMsg }));
} else if (err.status === 503) {
errMsg = 'Unable to Connect to Loop Server.';
this.store.dispatch(openAlert({
Expand All @@ -171,7 +171,7 @@ export class LoopService implements OnDestroy {
if (err.status === 401) {
errMsg = 'Unauthorized User.';
this.logger.info('Redirecting to Login');
this.store.dispatch(logout());
this.store.dispatch(logout({ payload: errMsg }));
} else if (err.status === 503) {
errMsg = 'Unable to Connect to Loop Server.';
setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/store/rtl.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const updateApplicationSettings = createAction(RTLActions.UPDATE_APPLICAT

export const setNodeData = createAction(RTLActions.SET_NODE_DATA, props<{ payload: GetInfoRoot }>());

export const logout = createAction(RTLActions.LOGOUT);
export const logout = createAction(RTLActions.LOGOUT, props<{ payload: string }>());

export const resetPassword = createAction(RTLActions.RESET_PASSWORD, props<{ payload: ResetPassword }>());

Expand Down
Loading

0 comments on commit e75cc2d

Please sign in to comment.