-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
618 additions
and
71 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,62 @@ | ||
// src/Login.tsx | ||
import React, { useState } from 'react'; | ||
import { signInWithEmailAndPassword } from 'firebase/auth'; | ||
import React, { useState, useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { signInWithEmailAndPassword, onAuthStateChanged } from 'firebase/auth'; | ||
import { auth } from '../firebaseconfig'; | ||
import { Button, Container, Stack, TextField, Typography } from '@mui/material'; | ||
|
||
// Justin | ||
// Justin & Syed | ||
const Login: React.FC = () => { | ||
const [email, setEmail] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
// Redirect if user is already logged in | ||
const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
if (user) { | ||
navigate('/'); // Redirect to homepage if authenticated | ||
} | ||
}); | ||
return () => unsubscribe(); // Cleanup listener on component unmount | ||
}, [navigate]); | ||
|
||
const handleLogin = async () => { | ||
try { | ||
await signInWithEmailAndPassword(auth, email, password); | ||
alert('Login Successful'); | ||
// The navigation will happen due to onAuthStateChanged listener | ||
} catch (error) { | ||
console.error("Error logging in:", error); | ||
alert((error as Error).message); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Login</h2> | ||
<input | ||
type="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
placeholder="Email" | ||
/> | ||
<input | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
placeholder="Password" | ||
/> | ||
<button onClick={handleLogin}>Login</button> | ||
</div> | ||
<Container maxWidth="xs" sx={{ mt: 4 }}> | ||
<Stack spacing={2} alignItems="center"> | ||
<Typography variant="h5">Login</Typography> | ||
<TextField | ||
label="Email" | ||
variant="outlined" | ||
fullWidth | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
<TextField | ||
label="Password" | ||
type="password" | ||
variant="outlined" | ||
fullWidth | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
<Button variant="contained" color="primary" onClick={handleLogin} fullWidth> | ||
Login | ||
</Button> | ||
</Stack> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Login; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,56 @@ | ||
import React from 'react'; | ||
import {Flex, Heading, MenuTrigger, ActionButton, Menu, Item} from '@adobe/react-spectrum'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Flex, Heading, MenuTrigger, ActionButton, Menu, Item } from '@adobe/react-spectrum'; | ||
import { getAuth, onAuthStateChanged, signOut } from 'firebase/auth'; | ||
import { Key } from 'react'; | ||
|
||
// Nishil | ||
// Nishil & Syed | ||
// Implements the top navigation bar | ||
const TopNavBar: React.FC = () => { | ||
return ( | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
const auth = getAuth(); | ||
|
||
useEffect(() => { | ||
const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
setIsLoggedIn(!!user); | ||
}); | ||
return () => unsubscribe(); | ||
}, [auth]); | ||
|
||
const handleSignOut = async () => { | ||
try { | ||
await signOut(auth); | ||
setIsLoggedIn(false); | ||
} catch (error) { | ||
console.error("Sign out failed", error); | ||
} | ||
}; | ||
|
||
<Flex margin="auto" justifyContent="space-between" alignItems="center" width="95%" height="100%"> | ||
<Heading level={1}>Metroll</Heading> | ||
<MenuTrigger> | ||
<ActionButton>☰</ActionButton> | ||
<Menu /*onAction={(key) => alert(key)}*/> | ||
<Item href="/login" key="login" >Login/Sign In</Item> | ||
<Item href="/" key="">Home</Item> | ||
<Item href="/about" key="about">About</Item> | ||
</Menu> | ||
</MenuTrigger> | ||
</Flex> | ||
const handleMenuOptions = (key: Key) => { | ||
if (key === 'signout') { | ||
handleSignOut(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Flex margin="auto" justifyContent="space-between" alignItems="center" width="95%" height="100%"> | ||
<Heading level={1}>Metroll</Heading> | ||
<MenuTrigger> | ||
<ActionButton>☰</ActionButton> | ||
<Menu onAction={handleMenuOptions}> | ||
{!isLoggedIn ? ( | ||
<Item href="/login" key="login">Login/Sign In</Item> | ||
) : ( | ||
<> | ||
<Item href="/account" key="account">Account</Item> | ||
<Item key="signout">Sign Out</Item> | ||
</> | ||
)} | ||
<Item href="/" key="home">Home</Item> | ||
<Item href="/about" key="about">About</Item> | ||
</Menu> | ||
</MenuTrigger> | ||
</Flex> | ||
); | ||
} | ||
}; | ||
|
||
export default TopNavBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from 'react'; | ||
import SvgIcon from '@mui/material/SvgIcon'; | ||
|
||
|
||
|
||
export function GoogleIcon() { | ||
return ( | ||
<SvgIcon> | ||
<svg | ||
width="16" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M15.68 8.18182C15.68 7.61455 15.6291 7.06909 15.5345 6.54545H8V9.64364H12.3055C12.1164 10.64 11.5491 11.4836 10.6982 12.0509V14.0655H13.2945C14.8073 12.6691 15.68 10.6182 15.68 8.18182Z" | ||
fill="#4285F4" | ||
/> | ||
<path | ||
d="M8 16C10.16 16 11.9709 15.2873 13.2945 14.0655L10.6982 12.0509C9.98545 12.5309 9.07636 12.8218 8 12.8218C5.92 12.8218 4.15273 11.4182 3.52 9.52727H0.858182V11.5927C2.17455 14.2036 4.87273 16 8 16Z" | ||
fill="#34A853" | ||
/> | ||
<path | ||
d="M3.52 9.52C3.36 9.04 3.26545 8.53091 3.26545 8C3.26545 7.46909 3.36 6.96 3.52 6.48V4.41455H0.858182C0.312727 5.49091 0 6.70545 0 8C0 9.29455 0.312727 10.5091 0.858182 11.5855L2.93091 9.97091L3.52 9.52Z" | ||
fill="#FBBC05" | ||
/> | ||
<path | ||
d="M8 3.18545C9.17818 3.18545 10.2255 3.59273 11.0618 4.37818L13.3527 2.08727C11.9636 0.792727 10.16 0 8 0C4.87273 0 2.17455 1.79636 0.858182 4.41455L3.52 6.48C4.15273 4.58909 5.92 3.18545 8 3.18545Z" | ||
fill="#EA4335" | ||
/> | ||
</svg> | ||
</SvgIcon> | ||
); | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters