Skip to content

Commit 5656c50

Browse files
committed
WIP firebase integrations
1 parent 1669eac commit 5656c50

File tree

13 files changed

+825
-7
lines changed

13 files changed

+825
-7
lines changed

package-lock.json

Lines changed: 655 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
"@apollo/react-hooks": "^3.1.5",
1818
"@types/react": "^16.9.35",
1919
"apollo-boost": "^0.4.9",
20+
"firebase": "^7.15.0",
2021
"graphql": "^15.0.0",
2122
"node-sass": "^4.14.1",
2223
"parcel-bundler": "^1.12.4",
2324
"react": "^16.13.1",
24-
"react-dom": "^16.13.1"
25+
"react-dom": "^16.13.1",
26+
"react-router-dom": "^5.2.0"
2527
}
2628
}

src/App.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom';
3+
import {
4+
BrowserRouter as Router,
5+
Switch,
6+
Route,
7+
Link
8+
} from "react-router-dom";
9+
10+
11+
// paths
12+
import Login from './components/Login'
13+
import Register from './components/Register'
14+
315
import './scss/main.scss'
16+
17+
18+
// router
19+
420
import { ApolloProvider } from '@apollo/react-hooks'
521
import ShowCountries from '../src/components/ShowCountries'
622
import ApolloClient from 'apollo-boost'
@@ -10,12 +26,18 @@ const client = new ApolloClient({
1026
})
1127

1228
const App = () => {
29+
1330
return (
14-
<ApolloProvider client={client}>
15-
<div className="">
16-
<ShowCountries/>
17-
</div>
18-
</ApolloProvider>
31+
<Router>
32+
<Route path="/login" component={Login} />
33+
<Route path="/signup" component={Register} />
34+
</Router>
35+
36+
// <ApolloProvider client={client}>
37+
// <div className="">
38+
// {/* <ShowCountries/> */}
39+
// </div>
40+
// </ApolloProvider>
1941
)
2042
}
2143

src/Firebase/config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Firebase App (the core Firebase SDK) is always required and
2+
// must be listed before other Firebase SDKs
3+
import * as firebase from "firebase/app";
4+
5+
// Add the Firebase services that you want to use
6+
import "firebase/auth";
7+
8+
const config = {
9+
apiKey: "AIzaSyAcPbOBP9js9jC6LGtm9ZjqwXjVpQjBQxM",
10+
authDomain: "react-firebase-fc06e.firebaseapp.com",
11+
databaseURL: "https://react-firebase-fc06e.firebaseio.com",
12+
projectId: "react-firebase-fc06e",
13+
storageBucket: "react-firebase-fc06e.appspot.com",
14+
messagingSenderId: "564100058598",
15+
appId: "1:564100058598:web:8c6ebd5ba04dc4faab1a27",
16+
measurementId: "G-GZNMEDXZPH"
17+
};
18+
19+
firebase.initializeApp(config)
20+
21+
export default config;

src/Routes/PrivateRoute.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// import React from 'react';
2+
// import { Route, Redirect } from 'react-router-dom'
3+
// import { AuthContext } from "../context/AuthContext";
4+
5+
// const PrivateRoute = ({ component: RouteComponent, ...rest }) => {
6+
// const {currentUser} = useContext(AuthContext);
7+
// return (
8+
// <Route
9+
// {...rest}
10+
// render={routeProps =>
11+
// !!currentUser ? (
12+
// <RouteComponent {...routeProps} />
13+
// ) : (
14+
// <Redirect to={"/login"} />
15+
// )
16+
// }
17+
// />
18+
// );
19+
// };
20+
21+
22+
// export default PrivateRoute

src/components/HomePage.js

Whitespace-only changes.

src/components/Login.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
const Login = () => {
4+
return(<div>
5+
6+
</div>)
7+
}
8+
9+
export default Login
10+
11+

src/components/Register.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { useState } from 'react';
2+
3+
const Register = () => {
4+
5+
const [email, setEmail] = useState('')
6+
const [pass, setPass] = useState('')
7+
8+
const onInputChange = (e, name) => {
9+
let inputValue = e.target.value
10+
if(name === 'pass') {
11+
setPass(inputValue)
12+
} if(name === 'email') {
13+
setEmail(inputValue)
14+
}
15+
}
16+
17+
18+
const registerUser = () => {
19+
20+
}
21+
22+
return(
23+
<div className="form">
24+
<div className="form-row">
25+
<label>Email</label>
26+
<input name="email" onChange={(e) => onInputChange(e,'email')}></input>
27+
</div>
28+
<div className="form-row">
29+
<label>Password</label>
30+
<input name="password" type="password" onChange={(e) => onInputChange(e, 'pass')}></input>
31+
</div>
32+
<button className="form-row">
33+
Login
34+
</button>
35+
36+
</div>)
37+
}
38+
39+
export default Register
40+
41+

src/components/_register.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.form {
2+
.form-row {
3+
margin-top: 12px;
4+
}
5+
}

src/context/AuthContext.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useEffect, useState } from 'react';
2+
import authConfig from '../Firebase/config'
3+
4+
export const AuthContext = React.createContext();
5+
6+
export const AuthProvider = ({ children }) => {
7+
const [currentUser, setCurrentUser] = useState(null);
8+
const [pending, setPending] = useState(true);
9+
10+
useEffect(() => {
11+
authConfig.auth().onAuthStateChanged((user) => {
12+
setCurrentUser(user)
13+
setPending(false)
14+
});
15+
}, []);
16+
17+
if(pending){
18+
return <>Loading...</>
19+
}
20+
21+
return (
22+
<AuthContext.Provider
23+
value={{
24+
currentUser
25+
}}
26+
>
27+
{children}
28+
</AuthContext.Provider>
29+
);
30+
};

0 commit comments

Comments
 (0)