web_next/scheduler_app/app/(routes)/dashboard/page.js

46 lines
No EOL
1.2 KiB
JavaScript

"use client"
import { LogoutLink, useKindeBrowserClient} from '@kinde-oss/kinde-auth-nextjs'
import React, { useEffect, useState } from 'react'
import { doc, getDoc, getFirestore } from "firebase/firestore";
import { app } from '@/config/FirebaseConfig';
import { useRouter } from 'next/navigation';
import Meeting from './meeting/page';
const Dashboard = () => {
const db = getFirestore(app);
const {user} = useKindeBrowserClient();
const [loading, setLoading] = useState(true);
const router = useRouter();
useEffect(() => {
user && isBusinessRegistered();
}, [user])
const isBusinessRegistered = async () => {
const docRef = doc(db, "Business", user.email);
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
setLoading(false);
} else {
// docSnap.data() will be undefined in this case
console.log("No such document!");
setLoading(false);
router.replace('/create_business');
}
}
if (loading){
return <p className='text-green-800 font-semibold justify-center items-center text-center py-10'>Loading...</p>
}
return (
<div>
<Meeting/>
</div>
)
}
export default Dashboard