From eae9242c199096fdf3f705bfa955a8eda6a2a56a Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Thu, 28 Mar 2019 16:26:24 +0530 Subject: [PATCH] Add login code --- src/index.js | 58 +++++++++++++++++++++++++++++++++++--------- src/sample.config.js | 4 +++ 2 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 src/sample.config.js diff --git a/src/index.js b/src/index.js index 6ffbf3a..72ac4fe 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,49 @@ -import React from 'react' -import ReactDOM from 'react-dom' -import './index.css' +import React, { useState } from "react"; +import ReactDOM from "react-dom"; +import PropTypes from "prop-types"; +import "./index.css"; +import { config } from "./config"; +import axios from "axios"; -class App extends Component { - render() { - return ( -
-

Hello, React!

-
- ) - }; +function auth(token) { + return axios.get(`${config.apiUrl}/auth?token=${encodeURIComponent(token)}`) + .then((res) => res.data.success); } -ReactDOM.render(, document.getElementById('root')); +function Login(props) { + const [input, setInput] = useState(""); + return ( +
+ setInput(evt.target.value)} /> + +
+ ); +} + +Login.propTypes = { + setLoggedIn: PropTypes.func, +}; + +function MainApp() { + return ( +
+
+ ); +} + +function App(){ + const [loggedIn, setLoggedIn] = useState(false); + if (loggedIn){ + return ( + + ); + } + else { + return ( + + ); + } +} + +ReactDOM.render(, document.getElementById("root")); diff --git a/src/sample.config.js b/src/sample.config.js new file mode 100644 index 0000000..d30912c --- /dev/null +++ b/src/sample.config.js @@ -0,0 +1,4 @@ +const config = { + apiUrl: "http://localhost:5000" +}; +export { config };