[ ADD ] react configuration
This commit is contained in:
10
react/src/utils/Auth.js
Normal file
10
react/src/utils/Auth.js
Normal file
@ -0,0 +1,10 @@
|
||||
// Service to check authentication for user and to signOut
|
||||
const Auth = {
|
||||
signOut() {
|
||||
localStorage.removeItem("token");
|
||||
},
|
||||
isAuth() {
|
||||
return localStorage.getItem("token");
|
||||
}
|
||||
};
|
||||
export default Auth;
|
1
react/src/utils/Constants.js
Normal file
1
react/src/utils/Constants.js
Normal file
@ -0,0 +1 @@
|
||||
export const BASE_URL = 'BASE_URL';
|
5
react/src/utils/LazyLoaded.js
Normal file
5
react/src/utils/LazyLoaded.js
Normal file
@ -0,0 +1,5 @@
|
||||
import React from "react";
|
||||
|
||||
export const Home = React.lazy(() => import('../containers/Home/Home'));
|
||||
export const Login = React.lazy(() => import('../containers/Login/Login'));
|
||||
export const NotFound = React.lazy(() => import('../components/NotFound/NotFound'));
|
18
react/src/utils/PrivateRoute.js
Normal file
18
react/src/utils/PrivateRoute.js
Normal file
@ -0,0 +1,18 @@
|
||||
import React from "react";
|
||||
import { Route, Redirect } from "react-router-dom";
|
||||
import Auth from "../utils/Auth";
|
||||
|
||||
const PrivateRoute = ({ component: Component, ...rest }) => {
|
||||
return (
|
||||
// Show the component only when the user is logged in
|
||||
// Otherwise, redirect the user to /signin page
|
||||
<Route
|
||||
{...rest}
|
||||
render={props =>
|
||||
Auth.isAuth() ? <Component {...props} /> : <Redirect to="/login" />
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default PrivateRoute;
|
18
react/src/utils/Shared.js
Normal file
18
react/src/utils/Shared.js
Normal file
@ -0,0 +1,18 @@
|
||||
import store from "../store";
|
||||
import { showSnackbarAction } from "../store/Snackbar/SnackbarAction";
|
||||
import messages from "../assets/Local/messages";
|
||||
|
||||
// To show error message that returned from backend
|
||||
export function dispatchSnackbarError(data) {
|
||||
if (data) {
|
||||
const errorMsg = data.error.message;
|
||||
store.dispatch(showSnackbarAction(errorMsg, "error"));
|
||||
}
|
||||
}
|
||||
// To show success message after any success request if needed and rendered from locale files
|
||||
export function dispatchSnackbarSuccess(message) {
|
||||
const lang = store.getState().lang;
|
||||
store.dispatch(
|
||||
showSnackbarAction(messages[lang].snackbar[message], "success")
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user