From 0943a0caa5e60e80346c311ef35a023c1e36f3a1 Mon Sep 17 00:00:00 2001 From: qianxuege Date: Sun, 22 Dec 2024 23:38:39 -0300 Subject: [PATCH] added login endpoint to app.py, implemented the redirect page --- frontend/src/pages/Welcome.tsx | 38 ++++++++++------------------------ frontend/src/types.ts | 9 +++++++- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/frontend/src/pages/Welcome.tsx b/frontend/src/pages/Welcome.tsx index f2e6efc..0bd5479 100644 --- a/frontend/src/pages/Welcome.tsx +++ b/frontend/src/pages/Welcome.tsx @@ -1,39 +1,22 @@ import React from "react"; -import { GoogleLogin } from "@react-oauth/google"; import { useNavigate } from "react-router-dom"; import axios from "axios"; -function GoogleSigninButton() { - let navigate = useNavigate(); +axios.defaults.withCredentials = true; - const routeChange = () => { - let path = `/home`; - navigate(path); - }; - - const handleLoginSuccess = async (credentialResponse: any) => { - - // Send the credential to your Flask backend +const Login: React.FC = () => { + const handleLogin = async () => { try { - const response = await axios.get('/login'); - console.log("Backend response:", response.data); - routeChange(); + const response = await axios.get('http://127.0.0.1:5000/login', { withCredentials: true }); + window.location.href = response.data.auth_url; // Redirect to Google login } catch (error) { - console.error("Error logging in:", error); + console.error('Login failed', error); } }; - return ( - <> - { - console.log("Login Failed"); - }} - /> - - ); -} + return ; +}; + const About: React.FC = () => { @@ -72,7 +55,8 @@ const Welcome: React.FC = () => { the all-in-one CMU resources platform
- + {/* */} +
diff --git a/frontend/src/types.ts b/frontend/src/types.ts index ca65646..fedadf8 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -132,4 +132,11 @@ export interface RemoveFCEventProps { calendarRef: React.RefObject, eventId: string } -export type RemoveFCEventType = ({calendarRef, eventId}: RemoveFCEventProps) => void; \ No newline at end of file +export type RemoveFCEventType = ({calendarRef, eventId}: RemoveFCEventProps) => void; + +export interface Event { + id: string; + summary: string; + start: { dateTime: string }; + end: { dateTime: string }; +} \ No newline at end of file