Skip to content

Commit

Permalink
ay
Browse files Browse the repository at this point in the history
  • Loading branch information
louisrli committed Jun 18, 2020
1 parent 21b487e commit 8712e3c
Showing 1 changed file with 1 addition and 60 deletions.
61 changes: 1 addition & 60 deletions src/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,7 @@ import db from "./firebase";
import firebase from "firebase";

const SignUpPage = () => {
// Check if user is logged in.
// https://firebase.google.com/docs/auth/web/manage-users
const [user, setUser] = React.useState(firebase.auth().currentUser);
const [profile, setProfile] = React.useState("");
const [city, setCity] = React.useState("");

const handleGoogleAuthClick = () => {
const provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then(function (result) {
const user = result.user;
setUser(user);
})
.catch(function (error) {
if (error) {
alert(JSON.stringify(error));
}
});
};

const handleSubmit = async (e) => {
e.preventDefault();
await db.collection("profiles").doc(user.uid).set({
userId: user.uid,
name: user.displayName,
profile: profile,
city: city,
imageUrl: user.photoURL,
});

alert("Submitted!");
};

return (
<div>
<Form>
<Form.Group>
{!user && (
<div onClick={handleGoogleAuthClick} style={{ cursor: "pointer" }}>
<img src={require("./google-signin.png")} />
</div>
)}
{user && <div>You're logged in as {user.email}</div>}
<Form.Control
placeholder="Profile"
onChange={(e) => setProfile(e.target.value)}
/>
<Form.Control
placeholder="City"
onChange={(e) => setCity(e.target.value)}
/>
<Button variant="primary" type="submit" onClick={handleSubmit}>
Submit
</Button>
</Form.Group>
</Form>
</div>
);
return <div></div>;
};

export default SignUpPage;

0 comments on commit 8712e3c

Please sign in to comment.