-
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.
Merge pull request #2 from NishilJ/login
Basic Auth implementation
- Loading branch information
Showing
15 changed files
with
288 additions
and
19 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { BrowserRouter as Router, Routes, Route} from 'react-router-dom'; | ||
import LoginPage from './pages/LoginPage'; | ||
import RegisterPage from "./pages/RegisterPage"; | ||
import AboutPage from "./pages/AboutPage"; | ||
import HomePage from './pages/HomePage'; | ||
|
||
// Nishil | ||
const App: React.FC = () => { | ||
|
||
return ( | ||
<Router> | ||
<Routes> | ||
<Route path="/" element={<HomePage />} /> | ||
<Route path="/login" element={<LoginPage/>} /> | ||
<Route path="/register" element={<RegisterPage />} /> | ||
<Route path="/about" element={<AboutPage />} /> | ||
</Routes> | ||
</Router> | ||
); | ||
}; | ||
|
||
|
||
|
||
export default App; |
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,25 @@ | ||
// src/GoogleSignIn.tsx | ||
import React from 'react'; | ||
import { signInWithPopup } from 'firebase/auth'; | ||
import { auth, googleProvider } from '../firebaseconfig'; | ||
|
||
// Justin | ||
const GoogleSSO: React.FC = () => { | ||
const handleGoogleSignIn = async () => { | ||
try { | ||
await signInWithPopup(auth, googleProvider); | ||
alert('Google Sign-In Successful'); | ||
} catch (error) { | ||
console.error("Error with Google Sign-In:", error); | ||
alert((error as Error).message); | ||
} | ||
}; | ||
|
||
return ( | ||
<button onClick={handleGoogleSignIn}> | ||
Sign in with Google | ||
</button> | ||
); | ||
}; | ||
|
||
export default GoogleSSO; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// src/Login.tsx | ||
import React, { useState } from 'react'; | ||
import { signInWithEmailAndPassword } from 'firebase/auth'; | ||
import { auth } from '../firebaseconfig'; | ||
|
||
// Justin | ||
const Login: React.FC = () => { | ||
const [email, setEmail] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
|
||
const handleLogin = async () => { | ||
try { | ||
await signInWithEmailAndPassword(auth, email, password); | ||
alert('Login Successful'); | ||
} 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> | ||
); | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// src/Register.tsx | ||
import React, { useState } from 'react'; | ||
import { createUserWithEmailAndPassword } from 'firebase/auth'; | ||
import { auth } from '../firebaseconfig'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
// Justin | ||
const Register: React.FC = () => { | ||
const [email, setEmail] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
const navigate = useNavigate(); | ||
const handleRegister = async () => { | ||
try { | ||
await createUserWithEmailAndPassword(auth, email, password); | ||
alert('Registration Successful'); | ||
navigate('/login'); | ||
} catch (error) { | ||
console.error("Error registering:", error); | ||
alert((error as Error).message); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Register</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={handleRegister}>Register</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Register; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import {Flex, Heading, MenuTrigger, ActionButton, Menu, Item} from '@adobe/react-spectrum'; | ||
|
||
// Nishil | ||
// Implements the top navigation bar | ||
const TopNavBar: React.FC = () => { | ||
return ( | ||
|
||
<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> | ||
); | ||
} | ||
|
||
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,18 @@ | ||
import React from 'react'; | ||
import {Flex, Item, ActionGroup} from '@adobe/react-spectrum'; | ||
|
||
// Nishil | ||
// Implements the three transit use case buttons | ||
const TransitBar: React.FC = () => { | ||
return ( | ||
<Flex margin="auto" alignItems="center" justifyContent="center" height="100%"> | ||
<ActionGroup selectionMode="single" width="fit-content" defaultSelectedKeys={['planner']}> | ||
<Item key="departures">Departures</Item> | ||
<Item key="planner">Trip Planner</Item> | ||
<Item key="routes">Routes</Item> | ||
</ActionGroup> | ||
</Flex> | ||
); | ||
} | ||
|
||
export default TransitBar; |
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,23 @@ | ||
// Import the functions you need from the SDKs you need | ||
import { initializeApp } from "firebase/app"; | ||
import { getAuth , GoogleAuthProvider} from 'firebase/auth'; | ||
|
||
// TODO: Add SDKs for Firebase products that you want to use | ||
// https://firebase.google.com/docs/web/setup#available-libraries | ||
|
||
// Your web app's Firebase configuration | ||
// For Firebase JS SDK v7.20.0 and later, measurementId is optional | ||
const firebaseConfig = { | ||
apiKey: "AIzaSyBctlGjVBPDHhr34jLPiHuQtNvY0Thx-k0", | ||
authDomain: "metroll-c924c.firebaseapp.com", | ||
projectId: "metroll-c924c", | ||
storageBucket: "metroll-c924c.appspot.com", | ||
messagingSenderId: "1012554613311", | ||
appId: "1:1012554613311:web:5b9deb9281b46d2edc6e8a", | ||
measurementId: "G-Q6DHKKY7V5" | ||
}; | ||
|
||
// Initialize Firebase | ||
const app = initializeApp(firebaseConfig); | ||
export const auth = getAuth(app); | ||
export const googleProvider = new GoogleAuthProvider(); |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import {defaultTheme, Provider} from "@adobe/react-spectrum"; | ||
import {useNavigate} from "react-router-dom"; | ||
|
||
const AboutPage: React.FC = () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Provider theme={defaultTheme}> | ||
<div> | ||
<button onClick={() => navigate('/')}>Home</button> | ||
<h2>About Page</h2> | ||
<p>This is the about page</p> | ||
</div> | ||
</Provider> | ||
); | ||
}; | ||
|
||
export default AboutPage; | ||
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// src/LoginPage.tsx | ||
import React from 'react'; | ||
import Login from '../components/Login'; | ||
import {useNavigate} from "react-router-dom"; | ||
import GoogleSignIn from "../components/GoogleSSO"; | ||
|
||
// Nishil & Justin | ||
const LoginPage: React.FC = () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<div> | ||
<button onClick={() => navigate('/')}>Home</button> | ||
<Login /> | ||
<GoogleSignIn /> | ||
<button onClick={() => navigate('/register')}>Go to Register</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoginPage; |
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,20 @@ | ||
// src/RegisterPage.tsx | ||
import React from 'react'; | ||
import Register from '../components/Register'; | ||
import {useNavigate} from "react-router-dom"; | ||
|
||
// Nishil & Justin | ||
const RegisterPage: React.FC = () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<div> | ||
<button onClick={() => navigate('/')}>Home</button> | ||
<Register /> | ||
<button onClick={() => navigate('/login')}>Go to Login</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RegisterPage; | ||
|