Skip to content

Commit

Permalink
Fix issue 100xDevs-hkirat#2: Added signin credentials to headers bloc…
Browse files Browse the repository at this point in the history
…k instead of body
  • Loading branch information
anuragshuklajec committed Sep 18, 2023
1 parent 5728fa5 commit 159bc43
Showing 1 changed file with 69 additions and 59 deletions.
128 changes: 69 additions & 59 deletions src/Signin.jsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,79 @@
import Button from '@mui/material/Button';
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import {Card, Typography} from "@mui/material";
import {useState} from "react";
import { Card, Typography } from "@mui/material";
import { useState } from "react";
import axios from "axios";

function Signin() {
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");

return <div>
<div style={{
paddingTop: 150,
marginBottom: 10,
display: "flex",
justifyContent: "center"
}}>
<Typography variant={"h6"}>
Welcome to Coursera. Sign up below
</Typography>
</div>
<div style={{display: "flex", justifyContent: "center"}}>
<Card varint={"outlined"} style={{width: 400, padding: 20}}>
<TextField
onChange={(evant11) => {
let elemt = evant11.target;
setEmail(elemt.value);
}}
fullWidth={true}
label="Email"
variant="outlined"
/>
<br/><br/>
<TextField
onChange={(e) => {
setPassword(e.target.value);
}}
fullWidth={true}
label="Password"
variant="outlined"
type={"password"}
/>
<br/><br/>
return (
<div>
<div
style={{
paddingTop: 150,
marginBottom: 10,
display: "flex",
justifyContent: "center",
}}
>
<Typography variant={"h6"}>
Welcome to Coursera. Sign up below
</Typography>
</div>
<div style={{ display: "flex", justifyContent: "center" }}>
<Card varint={"outlined"} style={{ width: 400, padding: 20 }}>
<TextField
onChange={(evant11) => {
let elemt = evant11.target;
setEmail(elemt.value);
}}
fullWidth={true}
label="Email"
variant="outlined"
/>
<br />
<br />
<TextField
onChange={(e) => {
setPassword(e.target.value);
}}
fullWidth={true}
label="Password"
variant="outlined"
type={"password"}
/>
<br />
<br />

<Button
size={"large"}
variant="contained"
onClick={async () => {
const res = await axios.post("http://localhost:3000/admin/login", {
username: email,
password: password
}, {
headers: {
"Content-type": "application/json"
}
});
const data = res.data;

localStorage.setItem("token", data.token);
window.location = "/"
}}
<Button
size={"large"}
variant="contained"
onClick={async () => {
const res = await axios.post(
"http://localhost:3000/admin/login",
{},
{
headers: {
username: email,
password: password,
},
}
);
const data = res.data;

> Signin</Button>
</Card>
</div>
localStorage.setItem("token", data.token);
window.location = "/";
}}
>
{" "}
Signin
</Button>
</Card>
</div>
</div>
);
}

export default Signin;
export default Signin;

0 comments on commit 159bc43

Please sign in to comment.