Skip to content

Commit

Permalink
add login check (ledger page)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuechengHao626 committed Oct 7, 2024
1 parent 99542f2 commit c92988c
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/app/ledger/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,60 @@
"use client";

import React, { useState } from 'react';
import React, { useState,useEffect } from 'react';
import Image from 'next/image';
import Detail from "../detail/page";
import AddPage from "../addPage/page";
import PieChartComponent from '../components/pieChart';
import { useRouter } from "next/navigation";
import { useAuth } from "../context/AuthContext";
import { auth } from "../config/firebaseConfig";
import { signOut } from "firebase/auth";
import BackgroundWrapper from "../components/BackgroundWrapper";
import {
Container,
Box,
Typography,
CircularProgress,
Grid,
Avatar,
} from "@mui/material";

const LedgerPage: React.FC = () => {
const [showModal, setShowModal] = useState(false);
const [refreshDetail, setRefreshDetail] = useState(false); // 用于控制 Detail 刷新
const [showPieChart, setShowPieChart] = useState(false);
const router = useRouter();
const { uid, isLoggedIn, setUid } = useAuth();
const [loading, setLoading] = useState(true);

useEffect(() => {
console.log("uid" + uid);

if (!isLoggedIn) {
setLoading(false);

router.replace("/login");
} else if (uid) {
console.log("succeed");
setLoading(false);


}
}, [isLoggedIn, uid, router]);

if (loading) {
return (
<BackgroundWrapper>
<Box
display="flex"
justifyContent="center"
alignItems="center"
minHeight="100vh"
>
<CircularProgress />
</Box>
</BackgroundWrapper>
);
}

const toggleModal = () => {
setShowModal(!showModal);
Expand Down

0 comments on commit c92988c

Please sign in to comment.