diff --git a/src/App.js b/src/App.js index 5c31532..f2087e7 100644 --- a/src/App.js +++ b/src/App.js @@ -1,8 +1,11 @@ import React, { Component } from 'react' +import axios from 'axios'; import { BrowserRouter, Route, Switch } from 'react-router-dom' +import { useState, useEffect } from 'react'; import './scss/style.scss' import ForgotPassword from './views/pages/register/ForgotPassword' import NewRegister from './views/pages/register/NewRegister' +import ProtectedRoute from './components/ProtectedRoute'; const loading = (
@@ -25,23 +28,22 @@ class App extends Component { - } /> + < Route exact path="/" name="Login Page" render={(props) => } /> + } /> } /> - - - - {/* } /> */} - {/* } - /> */} } /> } /> + + + {/* localStorage.getItem('authToken') ? */} } /> + {/* < ProtectedRoute path="/" name="Home" render={(props) => } /> */} + + + + diff --git a/src/components/ProtectedRoute.js b/src/components/ProtectedRoute.js new file mode 100644 index 0000000..4bc87db --- /dev/null +++ b/src/components/ProtectedRoute.js @@ -0,0 +1,18 @@ +import React, { useEffect, useState, } from "react"; +import { useHistory } from "react-router-dom"; +const ProtectedRoute = (props) => { + let Cmp = props; + const history = useHistory(); + useEffect(() => { + if (!localStorage.getItem('authToken')) + history.push('/') + }, []) + return ( + <> + + {/* {...props} */} + + ) +} + +export default ProtectedRoute \ No newline at end of file diff --git a/src/index.js b/src/index.js index dc8165f..34efee9 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,7 @@ import axios from 'axios' const setupAxios = () => { axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/'; - // axios.defaults.baseURL = 'http://localhost:5000' + //axios.defaults.baseURL = 'http://localhost:5000' axios.defaults.headers = { 'Cache-Control': 'no-cache,no-store', 'Pragma': 'no-cache', diff --git a/src/views/Directory/EditBisuness.js b/src/views/Directory/EditBisuness.js index 70cddc3..9018459 100644 --- a/src/views/Directory/EditBisuness.js +++ b/src/views/Directory/EditBisuness.js @@ -102,7 +102,7 @@ const EditBisuness = () => { let res = await axios.put( `/api/directory/update/${id}`, { - state, + ...state, }, { headers: { diff --git a/src/views/pages/login/Login.js b/src/views/pages/login/Login.js index ce7fc8e..ca5ddaf 100644 --- a/src/views/pages/login/Login.js +++ b/src/views/pages/login/Login.js @@ -31,8 +31,8 @@ const Login = () => { }; const Login = async () => { - const res = await axios.post("/owner/signin", auth); - if (res.data.status == "ok") { + const res = await axios.post("/api/user/login/", auth); + if (res.data.success == true) { localStorage.setItem("authToken", res.data.token) console.log(res.data) localStorage.setItem("auth", JSON.stringify({ @@ -61,7 +61,7 @@ const Login = () => {

Login

-

Sign In to your account

+

Sign In to Your CMP Dashboard Account.

@@ -93,20 +93,20 @@ const Login = () => {
- + {/* Forgot password? - + */}
- + {/* dont have an account? Sign Up - + */}