-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
login con google y stored on firebase
- Loading branch information
Showing
15 changed files
with
821 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,85 @@ | ||
import { Switch, Route } from "react-router-dom"; | ||
import { Switch, Route, Redirect } from "react-router-dom"; | ||
import React, { Component } from "react"; | ||
import { auth, handleUserProfile } from "./firebase/utils"; | ||
import "./default.scss"; | ||
// layouts | ||
import MainLayout from "./layouts/MainLayout"; | ||
import HomepageLayout from "./layouts/HomepageLayout"; | ||
// pages | ||
import Homepage from "./pages/Homepage"; | ||
import Registration from "./pages/Registration"; | ||
import Login from "./pages/Login"; | ||
|
||
const App = () => { | ||
return ( | ||
<div className="App"> | ||
<Switch> | ||
<Route | ||
exact | ||
path="/" | ||
render={() => ( | ||
<HomepageLayout> | ||
<Homepage /> | ||
</HomepageLayout> | ||
)} | ||
/> | ||
<Route | ||
path="/registration" | ||
render={() => ( | ||
<MainLayout> | ||
<Registration /> | ||
</MainLayout> | ||
)} | ||
/> | ||
</Switch> | ||
</div> | ||
); | ||
}; | ||
const initialState = { currentUser: null }; | ||
|
||
class App extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
...initialState, | ||
}; | ||
} | ||
authListener = null; | ||
componentDidMount() { | ||
this.authListener = auth.onAuthStateChanged(async (userAuth) => { | ||
if (userAuth) { | ||
const userRef = await handleUserProfile(userAuth); | ||
userRef.onSnapshot((snapshot) => { | ||
this.setState({ | ||
currentUser: { | ||
id: snapshot.id, | ||
...snapshot.data(), | ||
}, | ||
}); | ||
}); | ||
} | ||
this.setState({ | ||
...initialState, | ||
}); | ||
}); | ||
} | ||
componentWillUnmount() { | ||
this.authListener(); | ||
} | ||
|
||
render() { | ||
const { currentUser } = this.state; | ||
return ( | ||
<div className="App"> | ||
<Switch> | ||
<Route | ||
exact | ||
path="/" | ||
render={() => ( | ||
<HomepageLayout currentUser={currentUser}> | ||
<Homepage /> | ||
</HomepageLayout> | ||
)} | ||
/> | ||
<Route | ||
path="/registration" | ||
render={() => ( | ||
<MainLayout currentUser={currentUser}> | ||
<Registration /> | ||
</MainLayout> | ||
)} | ||
/> | ||
<Route | ||
path="/login" | ||
render={() => | ||
currentUser ? ( | ||
<Redirect to="/" /> | ||
) : ( | ||
<MainLayout currentUser={currentUser}> | ||
<Login /> | ||
</MainLayout> | ||
) | ||
} | ||
/> | ||
</Switch> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
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
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,31 @@ | ||
import React, { Component } from "react"; | ||
import "./styles.scss"; | ||
import Button from "./../forms/Button"; | ||
import { signInWitGoogle } from "./../../firebase/utils"; | ||
|
||
class SignIn extends Component { | ||
handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="signin"> | ||
<div className="wrap"> | ||
<h2>LogIn</h2> | ||
<div className="formWrap"> | ||
<form onSubmit={this.handleSubmit}> | ||
<div className="socialSignin"> | ||
<div className="row"> | ||
<Button onClick={signInWitGoogle}>Sign in with Google</Button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default SignIn; |
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,27 @@ | ||
.signing { | ||
display: block; | ||
width: 100%; | ||
max-width: 40rem; | ||
margin: 4rem auto 6rem; | ||
border: 1px solid black; | ||
|
||
.wrap { | ||
padding: 10px; | ||
|
||
h2 { | ||
font-size: 2.2rem; | ||
line-height: 1; | ||
font-weight: 400; | ||
text-transform: uppercase; | ||
text-align: center; | ||
display: block; | ||
padding: 0; | ||
width: 100%; | ||
margin: 0 auto; | ||
} | ||
|
||
.socialSignin { | ||
margin: 3rem auto 0; | ||
} | ||
} | ||
} |
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,11 @@ | ||
import React from "react"; | ||
import "./styles.scss"; | ||
|
||
const Button = ({ children, ...otherProps }) => { | ||
return ( | ||
<button className="btn" {...otherProps}> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
export default Button; |
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,15 @@ | ||
.btn { | ||
display: block; | ||
width: 100%; | ||
color: white; | ||
font-size: 1.8rem; | ||
line-height: 1; | ||
font-weight: 300; | ||
background: black; | ||
padding: 1rem 0; | ||
margin: 0 auto; | ||
text-transform: uppercase; | ||
border: 0; | ||
outline: none; | ||
cursor: pointer; | ||
} |
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,8 @@ | ||
export const firebaseConfig = { | ||
apiKey: "AIzaSyBrIueLrp0_zwsuA498J-2IN3nait-9TVo", | ||
authDomain: "ecom-solo.firebaseapp.com", | ||
projectId: "ecom-solo", | ||
storageBucket: "ecom-solo.appspot.com", | ||
messagingSenderId: "566504264771", | ||
appId: "1:566504264771:web:9b513cee7b5046a3a430f6", | ||
}; |
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,36 @@ | ||
import firebase from "firebase/app"; | ||
import "firebase/firestore"; | ||
import "firebase/auth"; | ||
import { firebaseConfig } from "./config"; | ||
|
||
firebase.initializeApp(firebaseConfig); | ||
|
||
export const auth = firebase.auth(); | ||
export const firestore = firebase.firestore(); | ||
|
||
const GoogleProvider = new firebase.auth.GoogleAuthProvider(); | ||
GoogleProvider.setCustomParameters({ prompt: "select_account" }); | ||
export const signInWitGoogle = () => auth.signInWithPopup(GoogleProvider); | ||
|
||
export const handleUserProfile = async (userAuth, additionalData) => { | ||
if (!userAuth) return; | ||
const { uid } = userAuth; | ||
const userRef = firestore.doc(`users/${uid}`); | ||
const snapshot = await userRef.get(); | ||
|
||
if (!snapshot.exists) { | ||
const { displayName, email } = userAuth; | ||
const timestamp = new Date(); | ||
try { | ||
await userRef.set({ | ||
displayName, | ||
email, | ||
createdDate: timestamp, | ||
...additionalData, | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
return userRef; | ||
}; |
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,13 @@ | ||
import React from "react"; | ||
import "./styles.scss"; | ||
import SignIn from "./../../components/SignIn"; | ||
|
||
const Login = (props) => { | ||
return ( | ||
<div> | ||
<SignIn /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Login; |
Empty file.