Skip to content

Commit 22b0032

Browse files
committed
Merge branch 'main' into Login
2 parents 056b0a3 + 4ed160a commit 22b0032

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

app/layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Metadata } from "next";
22
import { Montserrat } from "next/font/google";
33
import "./globals.css";
4-
//import Link from "next/link";
54

65
import Navbar from "@/components/navbar";
76
import Testbar from "@/components/testbar";
@@ -13,8 +12,6 @@ export const metadata: Metadata = {
1312
description: "Generated by create next app",
1413
};
1514

16-
17-
1815
// This is the height of the navbar which will also be used to set the padding-top of the main content
1916
// NOTE: you should modify this value to match the height of the navbar
2017
const navbarHeight: string = "60px";
@@ -32,9 +29,7 @@ export default function RootLayout({
3229

3330
{children}
3431
</div>
35-
3632
</body>
37-
3833
</html>
3934
);
4035
}

app/loginPage/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { GoogleOAuthProvider, useGoogleLogin, googleLogout, TokenResponse} from
44
import { jwtDecode } from "jwt-decode";
55
import axios from "axios";
66

7-
87
interface User {
98
name: string;
109
email: string;

app/page.tsx

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import { useState, useEffect } from "react";
33
import axios from "axios";
44
import Link from "next/link";
5+
import {
6+
GoogleOAuthProvider,
7+
GoogleLogin,
8+
googleLogout,
9+
} from "@react-oauth/google";
10+
import { jwtDecode } from "jwt-decode";
511

612
interface Food {
713
name: string;
@@ -15,7 +21,6 @@ interface subCategory {
1521
}
1622

1723
interface Category {
18-
forEach(arg0: (category: any) => void): unknown;
1924
name: string;
2025
sub_categories: Array<subCategory>;
2126
}
@@ -47,7 +52,7 @@ function ButtonLink(props: any) {
4752
);
4853
}
4954

50-
export default function Home() {
55+
function Home() {
5156
const [dhs, setDhs] = useState<DiningHall[]>([]);
5257
const [dhs_names, set_dhs_names] = useState([""]);
5358
const [searchInput, setSearchInput] = useState("");
@@ -80,7 +85,7 @@ export default function Home() {
8085
const allFoods: { food: Food; dhName: string; categoryName: string }[] = [];
8186
dhs.forEach((dh) => {
8287
dh.categories.forEach((category) => {
83-
category.sub_categories.forEach((subCategory: { foods: any[]; }) => {
88+
category.sub_categories.forEach((subCategory) => {
8489
subCategory.foods.forEach((food) => {
8590
allFoods.push({
8691
food,
@@ -155,7 +160,55 @@ export default function Home() {
155160
</h3>
156161

157162
</div>
158-
{/* Account Button */}
159163
</main>
160164
);
161165
}
166+
167+
export default function Page() {
168+
const [user, setUser] = useState<User | null>(null);
169+
170+
useEffect(() => {
171+
console.log(
172+
"Page component loaded and GoogleOAuthProvider should be active",
173+
);
174+
}, []);
175+
176+
const handleLogout = () => {
177+
googleLogout();
178+
setUser(null); // Clear user state on logout
179+
console.log("Logout Successful");
180+
};
181+
182+
const handleLoginSuccess = (credentialResponse: any) => {
183+
console.log("Login Successful", credentialResponse);
184+
const decoded: User = jwtDecode(credentialResponse.credential);
185+
setUser({
186+
name: decoded.name,
187+
picture: decoded.picture,
188+
});
189+
};
190+
191+
return (
192+
<GoogleOAuthProvider clientId="1040494859138-vji3ddfil5jancg23ifaginvmn71hktf.apps.googleusercontent.com">
193+
<Home />
194+
<GoogleLogin
195+
onSuccess={handleLoginSuccess}
196+
onError={() => {
197+
console.log("Login Failed");
198+
}}
199+
/>
200+
{user && (
201+
<div>
202+
<img src={user.picture} alt="User profile" />
203+
<h2>{user.name}</h2>
204+
</div>
205+
)}
206+
<button
207+
onClick={handleLogout}
208+
className="p-2 mt-2 text-white bg-red-600 rounded"
209+
>
210+
Logout
211+
</button>
212+
</GoogleOAuthProvider>
213+
);
214+
}

components/navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function Navbar({ height }: { height: string }) {
2525
</a>
2626
</li>
2727
<li>
28-
<a href="/loginPage" className="pl-4 pr-5">
28+
<a href="#" className="pl-4 pr-5">
2929
Account
3030
</a>
3131
{/* pr-X dicates how far off right we want. */}

db.sqlite3

-188 KB
Binary file not shown.

0 commit comments

Comments
 (0)