auth stuff

This commit is contained in:
Sir Blob
2025-01-26 03:31:43 -05:00
parent aa86349d41
commit 84fe04f3c4
6 changed files with 78 additions and 7 deletions

View File

@@ -2,9 +2,34 @@
import { PatientTable } from "./PatientTable"
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import axios from "axios";
import { useUser } from '@clerk/nextjs';
export default function Dashboard() {
const router = useRouter();
const { user } = useUser();
const [userData, setUserData] = useState(null);
useEffect(() => {
if (user) {
axios.get(`/api/user?userId=${user.id}`).then(response => {
setUserData(response.data);
});
}
}, [user]);
if (userData) {
if (userData.role !== "doctor") {
router.push("/suite/patient/dashboard");
}
} else {
router.push("/");
}
const patients = [
{ id: 1, name: "John Doe", age: 30, lastVisit: "2024-10-01" },
{ id: 2, name: "Jane Smith", age: 25, lastVisit: "2024-09-15" },