goodu
This commit is contained in:
parent
436d915f9f
commit
6ed0bda5f6
24
src/App.js
24
src/App.js
@ -1,8 +1,11 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
|
import axios from 'axios';
|
||||||
import { BrowserRouter, Route, Switch } from 'react-router-dom'
|
import { BrowserRouter, Route, Switch } from 'react-router-dom'
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
import './scss/style.scss'
|
import './scss/style.scss'
|
||||||
import ForgotPassword from './views/pages/register/ForgotPassword'
|
import ForgotPassword from './views/pages/register/ForgotPassword'
|
||||||
import NewRegister from './views/pages/register/NewRegister'
|
import NewRegister from './views/pages/register/NewRegister'
|
||||||
|
import ProtectedRoute from './components/ProtectedRoute';
|
||||||
|
|
||||||
const loading = (
|
const loading = (
|
||||||
<div className="pt-3 text-center">
|
<div className="pt-3 text-center">
|
||||||
@ -25,23 +28,22 @@ class App extends Component {
|
|||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<React.Suspense fallback={loading}>
|
<React.Suspense fallback={loading}>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/" name="Login Page" render={(props) => <Login {...props} />} />
|
< Route exact path="/" name="Login Page" render={(props) => <Login {...props} />} />
|
||||||
|
|
||||||
<Route exact path="/forgot" name="Forgot Page" render={(props) => <ForgotPassword {...props} />} />
|
<Route exact path="/forgot" name="Forgot Page" render={(props) => <ForgotPassword {...props} />} />
|
||||||
<Route exact path="/newRegister" name="Register Page" render={(props) => <NewRegister {...props} />} />
|
<Route exact path="/newRegister" name="Register Page" render={(props) => <NewRegister {...props} />} />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{/* <Route exact path="/comproducts/edit/:_id" name="commerce-product-edit" render={(props) => <EditProducts {...props} />} /> */}
|
|
||||||
{/* <Route
|
|
||||||
exact
|
|
||||||
path="/register"
|
|
||||||
name="Register Page"
|
|
||||||
render={(props) => <Register {...props} />}
|
|
||||||
/> */}
|
|
||||||
<Route exact path="/404" name="Page 404" render={(props) => <Page404 {...props} />} />
|
<Route exact path="/404" name="Page 404" render={(props) => <Page404 {...props} />} />
|
||||||
<Route exact path="/500" name="Page 500" render={(props) => <Page500 {...props} />} />
|
<Route exact path="/500" name="Page 500" render={(props) => <Page500 {...props} />} />
|
||||||
|
|
||||||
|
|
||||||
|
{/* localStorage.getItem('authToken') ? */}
|
||||||
<Route path="/" name="Home" render={(props) => <DefaultLayout {...props} />} />
|
<Route path="/" name="Home" render={(props) => <DefaultLayout {...props} />} />
|
||||||
|
{/* < ProtectedRoute path="/" name="Home" render={(props) => <DefaultLayout {...props} />} /> */}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
18
src/components/ProtectedRoute.js
Normal file
18
src/components/ProtectedRoute.js
Normal file
@ -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 (
|
||||||
|
<>
|
||||||
|
<Cmp />
|
||||||
|
{/* {...props} */}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProtectedRoute
|
@ -11,7 +11,7 @@ import axios from 'axios'
|
|||||||
|
|
||||||
const setupAxios = () => {
|
const setupAxios = () => {
|
||||||
axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
|
axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
|
||||||
// axios.defaults.baseURL = 'http://localhost:5000'
|
//axios.defaults.baseURL = 'http://localhost:5000'
|
||||||
axios.defaults.headers = {
|
axios.defaults.headers = {
|
||||||
'Cache-Control': 'no-cache,no-store',
|
'Cache-Control': 'no-cache,no-store',
|
||||||
'Pragma': 'no-cache',
|
'Pragma': 'no-cache',
|
||||||
|
@ -102,7 +102,7 @@ const EditBisuness = () => {
|
|||||||
let res = await axios.put(
|
let res = await axios.put(
|
||||||
`/api/directory/update/${id}`,
|
`/api/directory/update/${id}`,
|
||||||
{
|
{
|
||||||
state,
|
...state,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -31,8 +31,8 @@ const Login = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Login = async () => {
|
const Login = async () => {
|
||||||
const res = await axios.post("/owner/signin", auth);
|
const res = await axios.post("/api/user/login/", auth);
|
||||||
if (res.data.status == "ok") {
|
if (res.data.success == true) {
|
||||||
localStorage.setItem("authToken", res.data.token)
|
localStorage.setItem("authToken", res.data.token)
|
||||||
console.log(res.data)
|
console.log(res.data)
|
||||||
localStorage.setItem("auth", JSON.stringify({
|
localStorage.setItem("auth", JSON.stringify({
|
||||||
@ -61,7 +61,7 @@ const Login = () => {
|
|||||||
<CCardBody>
|
<CCardBody>
|
||||||
<CForm>
|
<CForm>
|
||||||
<h1>Login</h1>
|
<h1>Login</h1>
|
||||||
<p className="text-medium-emphasis">Sign In to your account</p>
|
<p className="text-medium-emphasis">Sign In to Your CMP Dashboard Account.</p>
|
||||||
<CInputGroup className="mb-3">
|
<CInputGroup className="mb-3">
|
||||||
<CInputGroupText>
|
<CInputGroupText>
|
||||||
<CIcon icon={cilUser} />
|
<CIcon icon={cilUser} />
|
||||||
@ -93,20 +93,20 @@ const Login = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<CButton color="link" className="px-0">
|
{/* <CButton color="link" className="px-0">
|
||||||
<Link to="/forgot">
|
<Link to="/forgot">
|
||||||
Forgot password?
|
Forgot password?
|
||||||
</Link>
|
</Link>
|
||||||
</CButton>
|
</CButton> */}
|
||||||
|
|
||||||
|
|
||||||
</CForm>
|
</CForm>
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
<CButton color="" className="px-0">
|
{/* <CButton color="" className="px-0">
|
||||||
<Link to="/newRegister">
|
<Link to="/newRegister">
|
||||||
dont have an account? Sign Up
|
dont have an account? Sign Up
|
||||||
</Link>
|
</Link>
|
||||||
</CButton>
|
</CButton> */}
|
||||||
</CCard>
|
</CCard>
|
||||||
|
|
||||||
</CCardGroup>
|
</CCardGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user