{
+ if (localStorage.getItem("token")) {
+ return ;
+ } else {
+ return ;
+ }
+ }}
+ />
+ );
+};
+
+export default PrivateRoute;
\ No newline at end of file
diff --git a/use/src/SignIn.js b/use/src/SignIn.js
index 4c1cb5d3..af7c7629 100644
--- a/use/src/SignIn.js
+++ b/use/src/SignIn.js
@@ -4,10 +4,11 @@ import {Card, Form, FormGroup, Input, Label, Button} from 'reactstrap';
import axios from 'axios';
import * as yup from 'yup';
import styled from 'styled-components';
+import axiosWithAuth from './axiosWithAuth/axiosWithAuth';
-const SignIn = () => {
+const SignIn = (props) => {
const [form, setForm] = useState({
- userName: "",
+ username: "",
password: ""
})
@@ -22,19 +23,31 @@ const SignIn = () => {
// validateChange(e);
setForm(newForm);
};
+
+ const inputSubmit = e => {
+ e.preventDefault();
+ axiosWithAuth()
+ .post("/auth/login", form)
+ .then( res => {
+ localStorage.setItem('token', res.data.token)
+ props.history.push('./TechList')
+ console.log(res);
+ });
+ }
+
return (
Don't have an account? Sign up here.
diff --git a/use/src/SignUp.js b/use/src/SignUp.js
index c13bcb72..1d773fbd 100644
--- a/use/src/SignUp.js
+++ b/use/src/SignUp.js
@@ -96,19 +96,18 @@ const SignUp = () => {
//placeholder api so I can see some data.
const formSubmit = e => {
e.preventDefault();
- console.log('default',e)
+ console.log('default', e)
axios
- .post('https://reqres.in/api/users', formData)
+ .post('https://usemy-techstuff.herokuapp.com/api/auth/register', formData)
.then(res => {
setUsers(res.data);
console.log('SET POST', res.data);
setFormData({
- name:'',
- email:'',
- password:'',
- terms: true
+ name: '',
+ email: '',
+ password: ''
});
// setServerError(null);
diff --git a/use/src/axiosWithAuth/axiosWithAuth.js b/use/src/axiosWithAuth/axiosWithAuth.js
new file mode 100644
index 00000000..fe73bc3f
--- /dev/null
+++ b/use/src/axiosWithAuth/axiosWithAuth.js
@@ -0,0 +1,14 @@
+import axios from "axios";
+
+const axiosWithAuth = () => {
+ const token = localStorage.getItem('token');
+
+ return axios.create({
+ baseURL: "https://usemy-techstuff.herokuapp.com/api",
+ headers: {
+ Authorization: token
+ }
+ });
+};
+
+export default axiosWithAuth;
\ No newline at end of file