resolving more linting issues

This commit is contained in:
cedricve
2021-01-06 10:16:31 +01:00
parent d2fc8b4847
commit 6b91c98a62
8 changed files with 66 additions and 32 deletions
+4 -1
View File
@@ -1,4 +1,7 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import {
render, screen, expect, test,
} from '@testing-library/react';
import App from './App';
test('renders Kerberos Open Source text', () => {
+20 -4
View File
@@ -1,7 +1,7 @@
import { push } from 'react-router-redux';
import { doLogin, doUpdateLicenseKey } from '../api/authentication';
import { doLogin, doCheckIfInstalled } from '../api/authentication';
export const login = (username, password) => function (dispatch) {
export const login = (username, password) => function dispatcher(dispatch) {
doLogin(username, password, (data) => {
// mark interface as logged in.
dispatch({
@@ -12,7 +12,7 @@ export const login = (username, password) => function (dispatch) {
expire: data.expire,
});
dispatch(push('/'));
}, (error, data) => {
}, (error) => {
dispatch({
type: 'LOGIN_FAILED',
error: error.message,
@@ -20,7 +20,23 @@ export const login = (username, password) => function (dispatch) {
});
};
export const logout = () => function (dispatch) {
export const checkIfInstalled = () => function dispatcher(dispatch) {
doCheckIfInstalled((data) => {
// Todo..
dispatch({
type: 'INSTALLED',
installed: data,
});
}, (error) => {
// Todo..
dispatch({
type: 'INSTALLED_ERROR',
error,
});
});
};
export const logout = () => function dispatcher(dispatch) {
dispatch({
type: 'LOGOUT',
});
+13 -11
View File
@@ -1,27 +1,29 @@
import axios from 'axios';
import config from '../config';
// import createAuthRefreshInterceptor from 'axios-auth-refresh';
import config from '../config.js';
const a = axios.create({
const axiosBase = axios.create({
baseURL: config.API_URL,
});
a.interceptors.request.use((request) => {
axiosBase.interceptors.request.use((request) => {
request.headers.Authorization = `Bearer ${localStorage.getItem('token')}`;
return request;
});
/* const refreshAuthLogic = failedRequest => a.get('refresh_token').then(tokenRefreshResponse => {
localStorage.setItem('token', tokenRefreshResponse.data.token);
localStorage.setItem('expire', tokenRefreshResponse.data.expire);
failedRequest.response.config.headers['Authentication'] = 'Bearer ' + tokenRefreshResponse.data.token;
return Promise.resolve();
export default axiosBase;
/* const refreshAuthLogic = failedRequest => axiosBase.get('refresh_token')
.then(tokenRefreshResponse => {
localStorage.setItem('token', tokenRefreshResponse.data.token);
localStorage.setItem('expire', tokenRefreshResponse.data.expire);
failedRequest.response.config.headers['Authentication'] = \
'Bearer ' + tokenRefreshResponse.data.token;
return Promise.resolve();
});
createAuthRefreshInterceptor(a, refreshAuthLogic); */
export default a;
export function getToken() {
return localStorage.getItem('token');
}
@@ -39,7 +41,7 @@ export function getAPI(baseURL) {
const a = axios.create({
baseURL,
});
a.interceptors.request.use((request) => {
axiosBase.interceptors.request.use((request) => {
request.headers.Authorization = `Bearer ${getToken()}`;
return request;
});
+3 -3
View File
@@ -23,7 +23,7 @@ export function doLogin(username, password, onSuccess, onError) {
});
}
export function checkIfInstalled(onSuccess, onError) {
export function doCheckIfInstalled(onSuccess, onError) {
API.get('api/installed')
.then((res) => {
if (res.status !== 200) {
@@ -43,10 +43,10 @@ export function checkIfInstalled(onSuccess, onError) {
});
}
export function doAuth(onSuccess, onError) {
/* export function doAuth(onSuccess, onError) {
}
export function doRefreshToken(onSuccess, onError) {
}
} */
@@ -1,9 +1,10 @@
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
// import Typography from '@material-ui/core/Typography';
import { login } from '../../actions';
import './LoginForm.css';
@@ -15,13 +16,14 @@ class LoginForm extends React.Component {
handleSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
this.props.dispatchLogin(data.get('username'), data.get('password'));
const { dispatchLogin } = this.props;
const { target } = event;
const data = new FormData(target);
dispatchLogin(data.get('username'), data.get('password'));
}
render() {
const { loginError, error } = this.props;
return (
<div className="paper-loginform">
{ loginError && <span className="error">{ error }</span> }
@@ -55,7 +57,7 @@ class LoginForm extends React.Component {
color="primary"
className="signin-button"
>
Let's Go
Let&apos;s Go
</Button>
<div className="shortcuts">
@@ -67,15 +69,21 @@ class LoginForm extends React.Component {
}
}
const mapStateToProps = (state, ownProps) => ({
const mapStateToProps = (state) => ({
loginError: state.auth.loginError,
error: state.auth.error,
});
const mapDispatchToProps = (dispatch, ownProps) => ({
const mapDispatchToProps = (dispatch) => ({
dispatchLogin: (username, password) => {
dispatch(login(username, password));
},
});
LoginForm.propTypes = {
loginError: PropTypes.bool.isRequired,
error: PropTypes.string.isRequired,
dispatchLogin: PropTypes.func.isRequired,
};
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(LoginForm));
+1 -2
View File
@@ -10,8 +10,7 @@ const dev = {
const prod = {
ENV: 'prod',
HOSTNAME: hostname,
API_URL: `${protocol}//${hostname}:8080/`,
// API_URL: window["env"]["apiUrl"] !== "" ? `${protocol}//${window["env"]["apiUrl"]}/` : `${protocol}//api.${hostname}/`,
API_URL: `${protocol}//${hostname}/api/`,
};
const config = process.env.REACT_APP_STAGE === 'production'
@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import PropTypes from 'prop-types';
export default function (ComposedComponent) {
export default function RequireAuth(ComposedComponent) {
class Auth extends React.Component {
componentDidMount() {
const {
@@ -18,9 +18,10 @@ export default function (ComposedComponent) {
}
render() {
const { isAuthenticated } = this.props;
return (
<div>
{ this.props.isAuthenticated ? <ComposedComponent {...this.props} /> : null }
{ isAuthenticated ? <ComposedComponent /> : null }
</div>
);
}
@@ -39,6 +40,8 @@ export default function (ComposedComponent) {
Auth.propTypes = {
isAuthenticated: PropTypes.bool.isRequired,
isInstalled: PropTypes.bool.isRequired,
redirectInstallation: PropTypes.func.isRequired,
redirectLogin: PropTypes.func.isRequired,
};
return connect(
@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import PropTypes from 'prop-types';
export default function Guest(ComposedComponent) {
export default function RequireGuest(ComposedComponent) {
class Guest extends React.Component {
componentDidMount() {
const {
@@ -18,9 +18,10 @@ export default function Guest(ComposedComponent) {
}
render() {
const { isAuthenticated } = this.props;
return (
<div>
{ !this.props.isAuthenticated ? <ComposedComponent {...this.props} /> : null }
{ !isAuthenticated ? <ComposedComponent /> : null }
</div>
);
}
@@ -39,6 +40,8 @@ export default function Guest(ComposedComponent) {
Guest.propTypes = {
isAuthenticated: PropTypes.bool.isRequired,
isInstalled: PropTypes.bool.isRequired,
redirectInstallation: PropTypes.func.isRequired,
redirectDashboard: PropTypes.func.isRequired,
};
return connect(