Add renew token and fix design

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-05-14 16:45:10 +02:00 committed by Alexandre Bodin
parent cc7db47a58
commit 9dd5ecf78d
11 changed files with 62 additions and 28 deletions

View File

@ -130,6 +130,15 @@ const unlockApp = () => {
dispatch(unfreezeApp()); dispatch(unfreezeApp());
}; };
const lockAppWithOverlay = () => {
const overlayblockerParams = {
children: <div />,
noGradient: true,
};
lockApp(overlayblockerParams);
};
window.strapi = Object.assign(window.strapi || {}, { window.strapi = Object.assign(window.strapi || {}, {
node: MODE || 'host', node: MODE || 'host',
env: NODE_ENV, env: NODE_ENV,
@ -165,6 +174,7 @@ window.strapi = Object.assign(window.strapi || {}, {
window.navigator.userLanguage || window.navigator.userLanguage ||
'en', 'en',
lockApp, lockApp,
lockAppWithOverlay,
unlockApp, unlockApp,
injectReducer, injectReducer,
injectSaga, injectSaga,

View File

@ -14,11 +14,9 @@
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Switch, Route } from 'react-router-dom'; import { Switch, Route } from 'react-router-dom';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux'; import { bindActionCreators, compose } from 'redux';
import { LoadingIndicatorPage, request } from 'strapi-helper-plugin'; import { LoadingIndicatorPage, auth, request } from 'strapi-helper-plugin';
import GlobalStyle from '../../components/GlobalStyle'; import GlobalStyle from '../../components/GlobalStyle';
import Admin from '../Admin'; import Admin from '../Admin';
import AuthPage from '../AuthPage'; import AuthPage from '../AuthPage';
@ -27,9 +25,7 @@ import NotFoundPage from '../NotFoundPage';
import NotificationProvider from '../NotificationProvider'; import NotificationProvider from '../NotificationProvider';
import PrivateRoute from '../PrivateRoute'; import PrivateRoute from '../PrivateRoute';
import Theme from '../Theme'; import Theme from '../Theme';
import { Content, Wrapper } from './components'; import { Content, Wrapper } from './components';
import { getDataSucceeded } from './actions'; import { getDataSucceeded } from './actions';
function App(props) { function App(props) {
@ -39,6 +35,24 @@ function App(props) {
useEffect(() => { useEffect(() => {
const getData = async () => { const getData = async () => {
const currentToken = auth.getToken();
if (currentToken) {
try {
const {
data: { token },
} = await request('/admin/renew-token', {
method: 'POST',
body: { token: currentToken },
});
auth.updateToken(token);
} catch (err) {
// Refresh app
auth.clearAppStorage();
window.location.reload();
}
}
try { try {
const requestURL = '/users-permissions/init'; const requestURL = '/users-permissions/init';

View File

@ -1,10 +1,9 @@
// TODO DELETE THIS FILE WHEN AUTH FINISHED
import React, { memo } from 'react'; import React, { memo } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
const CustomLabel = ({ id, values }) => ( const CustomLabel = ({ id, values }) => <FormattedMessage id={id} values={values} />;
<FormattedMessage id={id} values={values} />
);
CustomLabel.propTypes = { CustomLabel.propTypes = {
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,

View File

@ -1,3 +1,4 @@
// TODO DELETE THIS FILE WHEN AUTH FINISHED
import React, { memo } from 'react'; import React, { memo } from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';

View File

@ -1,3 +1,4 @@
// TODO DELETE THIS FILE WHEN AUTH FINISHED
import styled from 'styled-components'; import styled from 'styled-components';
// import Background from '../../assets/images/background_empty.svg'; // import Background from '../../assets/images/background_empty.svg';
@ -16,11 +17,11 @@ const Wrapper = styled.div`
// -webkit-font-smoothing: antialiased; // -webkit-font-smoothing: antialiased;
// .wrapper { // .wrapper {
// height: 22.1rem; // height: 22.1rem;
// width: 685px; // width: 685px;
// text-align: center; // text-align: center;
// background-image: url(${Background}); // background-image: url(${Background});
// background-position-x: center; // background-position-x: center;
// font-size: 1.4rem; // font-size: 1.4rem;
// font-family: Lato; // font-family: Lato;
// } // }

View File

@ -18,7 +18,7 @@ const Login = ({ formErrors, modifiedData, onChange, onSubmit, requestError }) =
<Section textAlign="center"> <Section textAlign="center">
<Logo /> <Logo />
</Section> </Section>
<Section> <Section withBackground>
<Padded top size="24px"> <Padded top size="24px">
<Box errorMessage={get(requestError, 'errorMessage', null)}> <Box errorMessage={get(requestError, 'errorMessage', null)}>
<form onSubmit={onSubmit}> <form onSubmit={onSubmit}>

View File

@ -1,10 +1,21 @@
import styled from 'styled-components'; import styled from 'styled-components';
import Background from '../../../../assets/images/background_empty.svg';
/* eslint-disable indent */
const Section = styled.section` const Section = styled.section`
text-align: ${({ textAlign }) => textAlign}; text-align: ${({ textAlign }) => textAlign};
${({ withBackground }) =>
withBackground &&
`
background-image: url(${Background});
background-position-x: center;
background-position-Y: center;
`}
`; `;
Section.defaultProps = { Section.defaultProps = {
withBackground: false,
textAlign: 'initial', textAlign: 'initial',
}; };

View File

@ -1,3 +1,4 @@
// TODO DELETE THIS FILE WHEN AUTH FINISHED
import * as yup from 'yup'; import * as yup from 'yup';
import { translatedErrors } from 'strapi-helper-plugin'; import { translatedErrors } from 'strapi-helper-plugin';

View File

@ -2,19 +2,8 @@ import React, { useEffect, useReducer } from 'react';
import { Padded } from '@buffetjs/core'; import { Padded } from '@buffetjs/core';
import axios from 'axios'; import axios from 'axios';
// import PropTypes from 'prop-types'; // import PropTypes from 'prop-types';
import { import { get, omit, upperFirst } from 'lodash';
get, import { Redirect, useRouteMatch, useHistory } from 'react-router-dom';
// isEmpty,
omit,
// set,
upperFirst,
} from 'lodash';
import {
// Link,
Redirect,
useRouteMatch,
useHistory,
} from 'react-router-dom';
import { auth } from 'strapi-helper-plugin'; import { auth } from 'strapi-helper-plugin';
import NavTopRightWrapper from '../../components/NavTopRightWrapper'; import NavTopRightWrapper from '../../components/NavTopRightWrapper';
import PageTitle from '../../components/PageTitle'; import PageTitle from '../../components/PageTitle';
@ -86,7 +75,6 @@ const AuthPage = () => {
}); });
// TODO register and other views logic // TODO register and other views logic
console.log(token);
auth.setToken(token, modifiedData.rememberMe); auth.setToken(token, modifiedData.rememberMe);
auth.setUserInfo(user, modifiedData.rememberMe); auth.setUserInfo(user, modifiedData.rememberMe);
@ -134,6 +122,8 @@ const AuthPage = () => {
export default AuthPage; export default AuthPage;
// TODO Remove comments when auth feature is finished
// import React, { memo, useEffect, useReducer, useRef } from 'react'; // import React, { memo, useEffect, useReducer, useRef } from 'react';
// import PropTypes from 'prop-types'; // import PropTypes from 'prop-types';
// import { get, isEmpty, omit, set, upperFirst } from 'lodash'; // import { get, isEmpty, omit, set, upperFirst } from 'lodash';

View File

@ -1,3 +1,4 @@
// TODO DELETE THIS FILE WHEN AUTH FINISHED
import { get } from 'lodash'; import { get } from 'lodash';
const formatErrorFromRequest = errorResponse => { const formatErrorFromRequest = errorResponse => {

View File

@ -85,6 +85,12 @@ const auth = {
setUserInfo(value = '', isLocalStorage = false, userInfo = USER_INFO) { setUserInfo(value = '', isLocalStorage = false, userInfo = USER_INFO) {
return auth.set(value, userInfo, isLocalStorage); return auth.set(value, userInfo, isLocalStorage);
}, },
updateToken(value = '') {
const isLocalStorage = localStorage && localStorage.getItem(TOKEN_KEY);
return auth.setToken(value, isLocalStorage);
},
}; };
export default auth; export default auth;