-
-
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
79d1b2b
commit 22d0360
Showing
12 changed files
with
224 additions
and
229 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import backBtnSound from "./backBtn.mp3"; | ||
import errorSound from "./error.mp3"; | ||
import successSound from "./success.mp3"; | ||
import lightOnSound from "./lightOn.mp3"; | ||
import lightOffSound from "./lightOff.mp3"; | ||
import lightOnSound from "./lightOn.mp3"; | ||
import successSound from "./success.mp3"; | ||
|
||
export { backBtnSound, errorSound, successSound, lightOnSound, lightOffSound }; | ||
export {backBtnSound, errorSound, lightOffSound, lightOnSound, successSound}; |
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,50 +1,51 @@ | ||
import { auth, db, facebookProvider, googleProvider } from "../lib/firebase"; | ||
import { playErrorSound, playSuccessSound } from "./sounds"; | ||
import {auth, db, facebookProvider, googleProvider} from "../lib/firebase"; | ||
|
||
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, | ||
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", | ||
}); | ||
} | ||
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", | ||
}); | ||
} | ||
}); | ||
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.