Skip to content

Commit

Permalink
fix auth
Browse files Browse the repository at this point in the history
  • Loading branch information
xWyvernPx committed Nov 7, 2023
1 parent eed231e commit e96f73a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/base/page/auth/sections/FirebaseSocial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 8 additions & 4 deletions src/base/store/context/FirebaseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -36,6 +37,7 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement })
useEffect(() => {

onAuthStateChanged(auth, (user) => {

if (user) {
dispatch({
isLoggedIn: true,
Expand All @@ -52,8 +54,7 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement })
isLoggedIn: false,
user: null,
isInitialized : false
});
}
}); }
});
}, [dispatch]);

Expand All @@ -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);
Expand All @@ -93,7 +96,8 @@ export const FirebaseProvider = ({ children }: { children: React.ReactElement })
...state,
firebaseRegister,
firebaseEmailPasswordSignIn,
login: () => {console.log("login");
login: () => {
window.location.href ="/"
},
firebaseGoogleSignIn,
firebaseTwitterSignIn,
Expand Down
7 changes: 5 additions & 2 deletions src/modules/order/hook/useOrderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrderAdmin>();
Expand All @@ -18,7 +20,8 @@ const useOrderData = (enable?: boolean) => {
const [id, setId] = useState<string>();
const [totalRows, setTotalRows] = useState<number>(0);
const [filter, setFilter] = useState<FilterState>({});

const auth = useRecoilValue(authState);

// Define the fetchOrderDataFunction that fetches orders using the OrderApi
const fetchOrderDataFunction = async () => {
try {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/utils/errorTracking/sentry/index.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down

0 comments on commit e96f73a

Please sign in to comment.