wirm/Web/public/js/ebcd-profile.js

34 lines
880 B
JavaScript
Raw Normal View History

2025-02-13 20:58:12 +08:00
import { auth } from "./ebcd-common-firebase.js";
console.log("ebcd-profile loaded <3");
// check url params
const urlParams = new URLSearchParams(window.location.search);
// if logOut=true, sign out
if (urlParams.get("logOut") === "true") {
auth
.signOut()
.then(() => {
2025-02-14 21:22:17 +08:00
console.log("ebcd-profile: signed out");
2025-02-13 20:58:12 +08:00
window.location = "/";
})
.catch((error) => {
console.error("ebcd-profile: error signing out", error);
2025-02-14 21:22:17 +08:00
window.location = "/";
2025-02-13 20:58:12 +08:00
});
}
2025-02-14 21:22:17 +08:00
// if we're signed in, reload the page with ?uid=...
auth.onAuthStateChanged((user) => {
if (!urlParams.has("uid")) {
// if we dont have a uid and we're signed in, redirect to /profile?uid=...
if (user) {
window.location = `/profile.html?uid=${user.uid}`;
} else {
// if we're not signed in, redirect to 404
window.location = "/404.html";
}
}
});