diff --git a/src/base/page/auth/sections/FirebaseSocial.tsx b/src/base/page/auth/sections/FirebaseSocial.tsx index 46c4231..f76af27 100644 --- a/src/base/page/auth/sections/FirebaseSocial.tsx +++ b/src/base/page/auth/sections/FirebaseSocial.tsx @@ -8,18 +8,20 @@ import { useTheme } from '@mui/material/styles'; import Facebook from '@/assets/images/icons/facebook.svg'; import Google from '@/assets/images/icons/google.svg'; import Twitter from '@/assets/images/icons/twitter.svg'; +import { useNavigate } from 'react-router-dom'; // ==============================|| FIREBASE - SOCIAL BUTTON ||============================== // const FirebaseSocial = () => { const theme = useTheme(); const matchDownSM = useMediaQuery(theme.breakpoints.down('sm')); - + const nav = useNavigate() const { firebaseFacebookSignIn, firebaseGoogleSignIn, firebaseTwitterSignIn } = useAuth(); const googleHandler = async () => { try { await firebaseGoogleSignIn(); + nav("/") } catch (err) { console.error(err); } diff --git a/src/base/store/context/FirebaseContext.tsx b/src/base/store/context/FirebaseContext.tsx index 85395e9..24dd7c2 100644 --- a/src/base/store/context/FirebaseContext.tsx +++ b/src/base/store/context/FirebaseContext.tsx @@ -4,6 +4,7 @@ import { FacebookAuthProvider, GoogleAuthProvider, TwitterAuthProvider, createUs import React, { createContext, useEffect } from 'react'; import { useRecoilState } from 'recoil'; import { authState } from '../atoms/auth'; +import { useNavigate } from 'react-router-dom'; const firebaseConfig = { apiKey: "AIzaSyDiyMFnM1CM6C4XUhLgHrtjloOjyk0ECz4", @@ -36,6 +37,7 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement }) useEffect(() => { onAuthStateChanged(auth, (user) => { + if (user) { dispatch({ isLoggedIn: true, @@ -52,8 +54,7 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement }) isLoggedIn: false, user: null, isInitialized : false - }); - } + }); } }); }, [dispatch]); @@ -76,7 +77,9 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement }) const firebaseRegister = async (email: string, password: string) => createUserWithEmailAndPassword(auth,email, password); - const logout = () => signOut(auth); + const logout = async () => { + window.location.href ="/login" + await signOut(auth)}; const resetPassword = async (email: string) => { await sendPasswordResetEmail(auth,email); @@ -93,7 +96,8 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement }) ...state, firebaseRegister, firebaseEmailPasswordSignIn, - login: () => {console.log("login"); + login: () => { + window.location.href ="/" }, firebaseGoogleSignIn, firebaseTwitterSignIn, diff --git a/src/modules/order/hook/useOrderData.ts b/src/modules/order/hook/useOrderData.ts index cc33c8e..97b2c76 100644 --- a/src/modules/order/hook/useOrderData.ts +++ b/src/modules/order/hook/useOrderData.ts @@ -6,6 +6,8 @@ import { useState } from "react"; import { useMutation, useQuery } from "react-query"; import { toast } from "react-toastify"; import OrderApi from "../service/order.api"; +import { useRecoilValue } from "recoil"; +import { authState } from "@/base/store/atoms/auth"; const useOrderData = (enable?: boolean) => { // const [orderData, setOrderData] = useState(); @@ -18,7 +20,8 @@ const useOrderData = (enable?: boolean) => { const [id, setId] = useState(); const [totalRows, setTotalRows] = useState(0); const [filter, setFilter] = useState({}); - + const auth = useRecoilValue(authState); + // Define the fetchOrderDataFunction that fetches orders using the OrderApi const fetchOrderDataFunction = async () => { try { @@ -96,7 +99,7 @@ const useOrderData = (enable?: boolean) => { }); const batchExportFunction = async ()=>{ const ApiEndpoint = `http://momkitchen.wyvernpserver.tech/api/v1/order?PageNumber=1&PageSize=50${keyword?"&KeySearch="+keyword:""}${!!filter?.to?.value ?? false? "&ToDate="+ moment(filter?.to?.value as string).add(30, "hours").add(59, "minutes").utc().toISOString() :""}${!!filter?.from?.value ?? false? "&FromDate="+ moment(filter?.from?.value as string).add(7, "hours").utc().toISOString() :""}${!!filter?.tab?.value ?? false? "&OrderStatus="+ filter?.tab?.value :""}`; - const EmailSender = "phonglethanh2@gmail.com"; + const EmailSender = auth?.user?.email ?? "phonglethanh2@gmail.com"; await OrderApi.exportOrder({ ApiEndpoint, EmailSender diff --git a/src/utils/errorTracking/sentry/index.ts b/src/utils/errorTracking/sentry/index.ts index a431835..a40e52f 100644 --- a/src/utils/errorTracking/sentry/index.ts +++ b/src/utils/errorTracking/sentry/index.ts @@ -1,8 +1,7 @@ import * as Sentry from "@sentry/react"; Sentry.init({ - dsn: import.meta.env.VITE_SENTRY_DSN, - + dsn: "https://a7168e5713f74609b399a46881fcbbe7@o4505181028679680.ingest.sentry.io/4505181031432192", integrations: [ new Sentry.BrowserTracing(), new Sentry.Replay(),