Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added_login_logic_frontend_backend #47

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Route, Routes } from "react-router-dom";
import { useEffect, useState } from "react";

import About from "./pages/About";
import Home from "./pages/Home";
Expand All @@ -7,17 +8,50 @@ import History from "./pages/History";
// import Header from "./Components/Header";
// import Footer from "./Components/Footer";

const App = () => (
<div>
{/* <Header /> */}
<Routes>
<Route path="/" element={<Home />} />
<Route path="/LandingPage" element={<LandingPage />} />
<Route path="/history" element={<History />} />
<Route path="/about/this/site" element={<About />} />
</Routes>
{/* <Footer /> */}
</div>
);
const App = () => {
const [user, setUser] = useState();

useEffect(() => {
const fetchUser = async () => {
try {
const response = await fetch(
"http://localhost:3000/api/auth/login/success" ??
"/api/auth/login/success",
{
method: "GET",
credentials: "include",
headers: {
Accept: "application/json",
"Content-type": "application/json",
"Access-Control-Allow-Credentials": true,
},
}
);
const json = await response.json();
const result = json;
//console.log(result);
//console.log("hey");
setUser(result);
} catch (error) {
//console.log("error", error);
return error;
}
};
fetchUser();
}, []);

return (
<div>
{/* <Header /> */}
<Routes>
<Route path="/" element={<Home user={user} />} />
<Route path="/LandingPage" element={<LandingPage />} />
<Route path="/history" element={<History />} />
<Route path="/about/this/site" element={<About />} />
</Routes>
{/* <Footer /> */}
</div>
);
};

export default App;
23 changes: 15 additions & 8 deletions client/src/Components/Header.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import logo from "../assets/cyf_brand.png";
import { Navbar, Button, Col } from "react-bootstrap";
import { Navbar, Button, Col, Card } from "react-bootstrap";
import ProfileIcone from "./ProfileIcone";
//header component
const Header = () => {
const Header = ({ user }) => {
return (
<>
<Navbar bg="light" expand="md" className="px-4">
Expand All @@ -21,7 +21,10 @@ const Header = () => {
xxl={2}
className="ms-auto justify-content-end d-flex"
>
<ProfileIcone />
{user ? (
<Card.Text style={{ marginTop: "12px" }}>{user.username}</Card.Text>
) : null}
<ProfileIcone user={user} />
</Col>
</Navbar>
<div
Expand All @@ -32,11 +35,15 @@ const Header = () => {
gridTemplateColumns: "1fr 4fr 1fr",
}}
>
<div></div>
<h6>
Our all-in-one writing helper tool is designed to reduce mistake,
improve grammar and suggest phrases
</h6>
<Col></Col>
<Col>
<div>
<h6>
Our all-in-one writing helper tool is designed to reduce mistake,
improve grammar and suggest phrases
</h6>
</div>
</Col>
<Col
xs={4}
md={3}
Expand Down
16 changes: 12 additions & 4 deletions client/src/Components/ProfileIcone.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { useState } from "react";
import { Modal, Button } from "react-bootstrap";
import icon from "../assets/Icon.png";
const ProfileIcone = () => {
const ProfileIcone = ({ user }) => {
const [show, setShow] = useState(false);

const logout = () => {
window.open("http://localhost:3000/api/auth/logout", "_self");
};

return (
<>
<Button
onClick={() => setShow(true)}
style={{ background: "transparent", border: "none" }}
>
<img
src={icon}
src={user ? user.avatar : icon}
alt="Icon"
style={{ width: "35px", height: "35px", borderRadius: "100%" }}
/>
Expand All @@ -26,11 +30,15 @@ const ProfileIcone = () => {
>
<Modal.Header closeButton>
<Modal.Title id="example-custom-modal-styling-title">
Profile
{user ? user.username : "Profile"}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Button>Sign Out</Button>
{user ? (
<Button type="submit" onClick={logout}>
Sign Out
</Button>
) : null}
</Modal.Body>
</Modal>
</>
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MainContent from "../Components/MainContent";
import "./Home.css";
// import logo from "./logo.svg"; //import for a logo

export function Home() {
export function Home({ user }) {
/* const [val, setVal] = useState("");
const [content, setContent] = useState("");*/
/*const [message, setMessage] = useState("Loading...");
Expand Down Expand Up @@ -73,7 +73,7 @@ export function Home() {

return (
<div>
<Header />
<Header user={user} />
{/* <p>Hello World</p>
this the label
<form id="inputForm" onSubmit={onSubmit}>
Expand Down
12 changes: 8 additions & 4 deletions client/src/pages/LandingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import Footer from "../Components/Footer";
import TeamLogo from "../assets/TeamLogo.png";
import Header from "../Components/Header";
const LandingPage = () => {
const github = () => {
window.open("http://localhost:3000/api/auth/github", "_self");
};

return (
<>
<Header />
Expand All @@ -22,14 +26,14 @@ const LandingPage = () => {
<Card.Body>
<Card.Title style={{ marginTop: "10%" }}>Welcome to TOOT</Card.Title>
<Card.Text>
<h6>
Log in with your GitHub account to <br /> continue
</h6>
Log in with your GitHub account to <br /> continue
</Card.Text>
<Button
href="/about/this/site"
type="submit"
//href="/about/this/site"
variant="danger "
style={{ marginTop: "20%" }}
onClick={github}
>
Log in with GitHub
</Button>
Expand Down
Loading
Loading