Skip to content

Commit

Permalink
added login endpoint to app.py, implemented the redirect page
Browse files Browse the repository at this point in the history
  • Loading branch information
qianxuege committed Dec 23, 2024
1 parent 546ae53 commit 0943a0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
38 changes: 11 additions & 27 deletions frontend/src/pages/Welcome.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<GoogleLogin
onSuccess={handleLoginSuccess}
onError={() => {
console.log("Login Failed");
}}
/>
</>
);
}
return <button onClick={handleLogin}>Login with Google</button>;
};



const About: React.FC = () => {
Expand Down Expand Up @@ -72,7 +55,8 @@ const Welcome: React.FC = () => {
the all-in-one CMU resources platform
</h2>
<div className="flex justify-center gap-8 pb-14">
<GoogleSigninButton />
{/* <GoogleSigninButton /> */}
<Login />
</div>
</div>

Expand Down
9 changes: 8 additions & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,11 @@ export interface RemoveFCEventProps {
calendarRef: React.RefObject<FullCalendar>,
eventId: string
}
export type RemoveFCEventType = ({calendarRef, eventId}: RemoveFCEventProps) => void;
export type RemoveFCEventType = ({calendarRef, eventId}: RemoveFCEventProps) => void;

export interface Event {
id: string;
summary: string;
start: { dateTime: string };
end: { dateTime: string };
}

0 comments on commit 0943a0c

Please sign in to comment.