-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
1 parent
22d0360
commit 74475d6
Showing
9 changed files
with
226 additions
and
212 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
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,51 +1,51 @@ | ||
import {auth, db, facebookProvider, googleProvider} from "../lib/firebase"; | ||
import { auth, db, facebookProvider, googleProvider } from "../lib/firebase"; | ||
|
||
import {playErrorSound, playSuccessSound} from "./sounds"; | ||
import { playErrorSound, playSuccessSound } from "./sounds"; | ||
|
||
const signInWithOAuth = (e, enqueueSnackbar, navigate, google = true) => { | ||
e.preventDefault(); | ||
const provider = google ? googleProvider : facebookProvider; | ||
auth.signInWithPopup(provider) | ||
.then(async (val) => { | ||
const userRef = | ||
db.collection("users").where("uid", "==", val?.user?.uid); | ||
auth | ||
.signInWithPopup(provider) | ||
.then(async (val) => { | ||
const userRef = db.collection("users").where("uid", "==", val?.user?.uid); | ||
|
||
const docSnap = await userRef.get(); | ||
if (docSnap.docs.length < 1) { | ||
const usernameDoc = db.collection("users"); | ||
await usernameDoc.doc(auth.currentUser.uid).set({ | ||
uid : val.user.uid, | ||
username : val.user.uid, | ||
name : val.user.displayName, | ||
photoURL : val.user.photoURL, | ||
displayName : val.user.displayName, | ||
Friends : [], | ||
posts : [], | ||
}); | ||
} else if (!docSnap.docs[0].data().username) { | ||
docSnap.docs[0].ref.update({ | ||
username : doc.data().uid, | ||
}); | ||
} | ||
playSuccessSound(); | ||
enqueueSnackbar("Login successful!", { | ||
variant : "success", | ||
const docSnap = await userRef.get(); | ||
if (docSnap.docs.length < 1) { | ||
const usernameDoc = db.collection("users"); | ||
await usernameDoc.doc(auth.currentUser.uid).set({ | ||
uid: val.user.uid, | ||
username: val.user.uid, | ||
name: val.user.displayName, | ||
photoURL: val.user.photoURL, | ||
displayName: val.user.displayName, | ||
Friends: [], | ||
posts: [], | ||
}); | ||
navigate("/"); | ||
}) | ||
.catch((error) => { | ||
if (error.code === "auth/account-exists-with-different-credential") { | ||
playErrorSound(); | ||
enqueueSnackbar("Account exists with a different credential", { | ||
variant : "error", | ||
}); | ||
} else { | ||
playErrorSound(); | ||
enqueueSnackbar(error.message, { | ||
variant : "error", | ||
}); | ||
} | ||
} else if (!docSnap.docs[0].data().username) { | ||
docSnap.docs[0].ref.update({ | ||
username: doc.data().uid, | ||
}); | ||
} | ||
playSuccessSound(); | ||
enqueueSnackbar("Login successful!", { | ||
variant: "success", | ||
}); | ||
navigate("/"); | ||
}) | ||
.catch((error) => { | ||
if (error.code === "auth/account-exists-with-different-credential") { | ||
playErrorSound(); | ||
enqueueSnackbar("Account exists with a different credential", { | ||
variant: "error", | ||
}); | ||
} else { | ||
playErrorSound(); | ||
enqueueSnackbar(error.message, { | ||
variant: "error", | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
export default signInWithOAuth; |
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
Oops, something went wrong.