diff --git a/src/components/layout/PushNotificationWrapper.tsx b/src/components/layout/PushNotificationWrapper.tsx
index 970eba5..5671a80 100644
--- a/src/components/layout/PushNotificationWrapper.tsx
+++ b/src/components/layout/PushNotificationWrapper.tsx
@@ -6,58 +6,92 @@ import { Toaster } from "react-hot-toast";
import { getMessaging, onMessage } from "firebase/messaging";
import { app } from "@/lib/auth/firebase";
import ToastService from "../widgets/toast";
+import { doc, setDoc } from "@firebase/firestore";
+import { useAuthUserContext } from "@/lib/auth/authUserContext";
+import { users } from "@/lib/db";
+import logger from "@/lib/util/logging";
+import { parseUserAgent } from "react-device-detect";
const PushNotificationWrapper = ({ children }: React.PropsWithChildren) => {
- const router = useRouter();
- useEffect(() => {
- setToken();
+ const router = useRouter();
+ const { profile } = useAuthUserContext();
+ useEffect(() => {
+ const _getAndStoreRegistrationToken = async () => {
+ const { ua } = parseUserAgent(window.navigator.userAgent);
- // Event listener that listens for the push notification event in the background
- if ("serviceWorker" in navigator) {
- navigator.serviceWorker.addEventListener("message", (event) => {
- console.log("event for the service worker", event);
+ if (!profile) return;
+ await setToken();
+
+ // Event listener that listens for the push notification event in the background
+ if ("serviceWorker" in navigator) {
+ navigator.serviceWorker.addEventListener("message", (event) => {
+ console.log("event for the service worker", event);
+ });
+ }
+
+ // Calls the getMessage() function if the token is there
+ async function setToken() {
+ try {
+ if (!profile) return;
+ const token = await firebaseCloudMessaging.init();
+ if (token && profile) {
+ const newRegistration = {
+ fcmToken: token,
+ deviceType: ua,
+ lastSeen: new Date()
+ };
+ const index = profile.deviceRegistrations?.findIndex(reg => {
+ return reg.fcmToken === token;
+ });
+ if (index !== undefined && index !== -1) {
+ if (profile.deviceRegistrations && profile.deviceRegistrations[index]) {
+ profile.deviceRegistrations[index] = newRegistration;
+ }
+ } else {
+ profile.deviceRegistrations?.push(newRegistration);
+ }
+ }
+ const profileWithRegistrations = Object.assign({}, profile);
+ await setDoc(doc(users, profile?.id), profileWithRegistrations, { merge: true });
+ getMessage();
+ } catch (error) {
+ console.log(error);
+ }
+ }
+ };
+ _getAndStoreRegistrationToken()
+ .catch(err => {
+ logger.error("PushNotificationWrapper", "_getAndStoreRegistrationToken_error", err);
+ });
+ }, [profile]);
+
+ function getMessage() {
+ const messaging = getMessaging(app);
+ onMessage(messaging, (message) => {
+ ToastService.custom(
+
+ message?.data?.url &&
+ handleClickPushNotification(message?.data?.url)
+ }
+ >
+
{message?.notification?.title}
+ {message?.notification?.body}
+
+ );
});
}
- // Calls the getMessage() function if the token is there
- async function setToken() {
- try {
- const token = await firebaseCloudMessaging.init();
- if (token) {
- console.log("token", token);
- getMessage();
- }
- } catch (error) {
- console.log(error);
- }
- }
- });
- function getMessage() {
- const messaging = getMessaging(app);
-
- onMessage(messaging, (message) => {
- ToastService.custom(
-
- message?.data?.url &&
- handleClickPushNotification(message?.data?.url)
- }
- >
-
{message?.notification?.title}
- {message?.notification?.body}
-
- );
- });
- }
- const handleClickPushNotification = (url: string) => {
- router.push(url);
- };
- return (
- <>
+ const handleClickPushNotification = (url: string) => {
+ router.push(url);
+ };
+ return (
+ <>
- {children}
+ {children}
>
- );
-};
+ );
+ }
+;
export default PushNotificationWrapper;
diff --git a/src/components/auth/LoginPage.tsx b/src/components/pages/auth/LoginPage.tsx
similarity index 100%
rename from src/components/auth/LoginPage.tsx
rename to src/components/pages/auth/LoginPage.tsx
diff --git a/src/components/pages/auth/SignupPage.tsx b/src/components/pages/auth/SignupPage.tsx
new file mode 100644
index 0000000..a81e3d0
--- /dev/null
+++ b/src/components/pages/auth/SignupPage.tsx
@@ -0,0 +1,157 @@
+"use client";
+import React from "react";
+import { useRouter } from "next/navigation";
+import useFirebaseAuth from "@/lib/auth/useFirebaseAuth";
+import { IoLogoFacebook, IoLogoGoogle, IoLogoTwitter } from "react-icons/io";
+
+const SignupPage = () => {
+ const { signInWithGoogle, signInWithFacebook, signInWithTwitter, profile, signUp } =
+ useFirebaseAuth();
+ const router = useRouter();
+ const [error, setError] = React.useState("");
+ const [email, setEmail] = React.useState("");
+ const [password, setPassword] = React.useState("");
+ const [confirmPassword, setConfirmPassword] = React.useState("");
+
+
+ const register = async (
+ $event: React.SyntheticEvent
+ ): Promise => {
+ $event.preventDefault();
+ const result = await signUp(email, password);
+ if (result === "auth/email-already-in-use") {
+ setError("This email address has already been used to create an account.");
+ } else if (result === "auth/invalid-email") {
+ setError("Please enter a correct email address");
+ } else {
+ setError("Unable to create an account for you at this time");
+ }
+ };
+ return (
+
+
+ Create New Account
+
+ {error && (
+
+ )}
+
+
+ );
+};
+
+export default SignupPage;
diff --git a/src/components/pages/auth/index.ts b/src/components/pages/auth/index.ts
new file mode 100644
index 0000000..fbbbb40
--- /dev/null
+++ b/src/components/pages/auth/index.ts
@@ -0,0 +1,4 @@
+import LoginPage from "./LoginPage";
+import SignupPage from "./SignupPage";
+
+export { LoginPage, SignupPage };
diff --git a/src/components/pages/profile/ProfilePageComponentProfile.tsx b/src/components/pages/profile/ProfilePageComponentProfile.tsx
index 800e885..689e52e 100644
--- a/src/components/pages/profile/ProfilePageComponentProfile.tsx
+++ b/src/components/pages/profile/ProfilePageComponentProfile.tsx
@@ -19,8 +19,7 @@ const ProfilePageComponentProfile = () => {
const [url, setUrl] = React.useState("");
const [image, setImage] = React.useState("");
React.useEffect(() => {
- console.log("ProfilePageComponentProfile", "useEffect", profile);
- if (profile) {
+ if (profile) {
setEmail(profile.email as string);
setDisplayName(profile.displayName as string);
setAbout(profile.about as string);
diff --git a/src/components/widgets/ui/themes/ThemeSelector.tsx b/src/components/widgets/ui/themes/ThemeSelector.tsx
index 38e667d..05fc443 100644
--- a/src/components/widgets/ui/themes/ThemeSelector.tsx
+++ b/src/components/widgets/ui/themes/ThemeSelector.tsx
@@ -5,21 +5,11 @@ import { useState, useEffect } from "react";
import { IoColorPaletteOutline } from "react-icons/io5";
import { BiDownArrow } from "react-icons/bi";
import { defaults } from "@/lib/constants";
+import { useTheme } from "react-daisyui";
+import { themeChange } from "theme-change";
const ThemeSelector = () => {
- const [activeTheme, setActiveTheme] = useState(
- typeof window !== "undefined" && localStorage.getItem("theme") ||
- defaults.defaultTheme);
- //
- useEffect(() => {
- if (document) {
- document.body.dataset.theme = activeTheme;
- window.localStorage.setItem("theme", activeTheme);
- }
- }, [activeTheme]);
-
- const _switchTheme = useCallback((theme: string) => {
- setActiveTheme(theme);
+ const _switchTheme = useCallback(() => {
const elem = document.activeElement as HTMLElement;
elem?.blur();
}, []);
@@ -39,7 +29,8 @@ const ThemeSelector = () => {