From 84fe04f3c4271a64cbb3f8c6967f5683403bf32b Mon Sep 17 00:00:00 2001 From: Sir Blob <76974209+GamerBoss101@users.noreply.github.com> Date: Sun, 26 Jan 2025 03:31:43 -0500 Subject: [PATCH] auth stuff --- .../(panels)/suite/doctor/account/page.jsx | 7 ++++- .../doctor/dashboard/{page.tsx => page.jsx} | 25 ++++++++++++++++++ .../(panels)/suite/patient/account/page.jsx | 11 +++++--- .../suite/patient/chat/{page.tsx => page.jsx} | 26 +++++++++++++++++++ .../(panels)/suite/patient/dashboard/page.jsx | 14 ++++++++-- tsconfig.json | 2 +- 6 files changed, 78 insertions(+), 7 deletions(-) rename src/app/(panels)/suite/doctor/dashboard/{page.tsx => page.jsx} (52%) rename src/app/(panels)/suite/patient/chat/{page.tsx => page.jsx} (68%) diff --git a/src/app/(panels)/suite/doctor/account/page.jsx b/src/app/(panels)/suite/doctor/account/page.jsx index 613633b..1d24a5a 100644 --- a/src/app/(panels)/suite/doctor/account/page.jsx +++ b/src/app/(panels)/suite/doctor/account/page.jsx @@ -12,7 +12,10 @@ import { ChevronDown } from "lucide-react" import { PersonForm } from './PatientForm'; +import { useRouter } from 'next/navigation'; + const AccountPage = () => { + const router = useRouter(); const { user } = useUser(); const [userData, setUserData] = useState(null); const [patients, setPatients] = useState([]); @@ -40,7 +43,9 @@ const AccountPage = () => { } }; - if (!userData) return
Loading...
; + if (!userData) { + router.push('/'); + } return (
diff --git a/src/app/(panels)/suite/doctor/dashboard/page.tsx b/src/app/(panels)/suite/doctor/dashboard/page.jsx similarity index 52% rename from src/app/(panels)/suite/doctor/dashboard/page.tsx rename to src/app/(panels)/suite/doctor/dashboard/page.jsx index 559038a..8ec6d5e 100644 --- a/src/app/(panels)/suite/doctor/dashboard/page.tsx +++ b/src/app/(panels)/suite/doctor/dashboard/page.jsx @@ -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" }, diff --git a/src/app/(panels)/suite/patient/account/page.jsx b/src/app/(panels)/suite/patient/account/page.jsx index 0798117..a435b98 100644 --- a/src/app/(panels)/suite/patient/account/page.jsx +++ b/src/app/(panels)/suite/patient/account/page.jsx @@ -7,6 +7,7 @@ import { Label } from '@/components/ui/label'; import { Card, CardHeader, CardContent } from '@/components/ui/card'; const AccountPage = () => { + const router = useRouter(); const { user } = useUser(); const [userData, setUserData] = useState(null); @@ -18,9 +19,13 @@ const AccountPage = () => { } }, [user]); - if (!userData) return
Loading...
; - - console.log(userData); + if (userData) { + if (userData.role !== "doctor") { + router.push("/suite/patient/dashboard"); + } + } else { + router.push("/"); + } return (
diff --git a/src/app/(panels)/suite/patient/chat/page.tsx b/src/app/(panels)/suite/patient/chat/page.jsx similarity index 68% rename from src/app/(panels)/suite/patient/chat/page.tsx rename to src/app/(panels)/suite/patient/chat/page.jsx index bf59c51..0ebf208 100644 --- a/src/app/(panels)/suite/patient/chat/page.tsx +++ b/src/app/(panels)/suite/patient/chat/page.jsx @@ -8,7 +8,33 @@ import { Input } from "@/components/ui/input" import { Card, CardContent } from "@/components/ui/card" +import { useRouter } from "next/navigation"; +import { useUser } from "@clerk/nextjs"; +import { useEffect, useState } from "react"; +import axios from "axios"; + + export default function Chat() { + 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("/"); + } + return (
diff --git a/src/app/(panels)/suite/patient/dashboard/page.jsx b/src/app/(panels)/suite/patient/dashboard/page.jsx index 5baf5a4..2a11161 100644 --- a/src/app/(panels)/suite/patient/dashboard/page.jsx +++ b/src/app/(panels)/suite/patient/dashboard/page.jsx @@ -3,13 +3,15 @@ import { useState, useEffect } from 'react'; import axios from 'axios'; import { useUser } from '@clerk/nextjs'; +import { useRouter } from 'next/navigation'; import { IntenseChart } from "./IntensityChart" import { MedicationTable } from "./MedicationTable" export default function Dashboard() { - const { user } = useUser(); + const router = useRouter(); + const { user } = useUser(); const [userData, setUserData] = useState(null); useEffect(() => { @@ -18,7 +20,15 @@ export default function Dashboard() { setUserData(response.data); }); } - }, [user]); + }, [user]); + + if (userData) { + if (userData.role !== "doctor") { + router.push("/suite/patient/dashboard"); + } + } else { + router.push("/"); + } return (
diff --git a/tsconfig.json b/tsconfig.json index d29ef96..ac07830 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,6 @@ "@/*": ["./src/*"] } }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app/api/connectDB.js", "src/lib/utils.js", "src/app/(web)/account/page.jsx", "src/app/(panels)/suite/patient/account/page.jsx", "src/app/(panels)/suite/patient/dashboard/MedicationTable.jsx", "src/app/(panels)/suite/patient/dashboard/page.jsx", "src/app/api/transcribe/route.js", "src/components/ui/calendar.jsx", "src/app/(web)/page.jsx", "src/app/(web)/transcribe/page.jsx", "src/app/(web)/login/page.jsx", "src/app/(panels)/suite/layout.jsx"], + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app/api/connectDB.js", "src/lib/utils.js", "src/app/(web)/account/page.jsx", "src/app/(panels)/suite/patient/account/page.jsx", "src/app/(panels)/suite/patient/dashboard/MedicationTable.jsx", "src/app/(panels)/suite/patient/dashboard/page.jsx", "src/app/api/transcribe/route.js", "src/components/ui/calendar.jsx", "src/app/(web)/page.jsx", "src/app/(web)/transcribe/page.jsx", "src/app/(web)/login/page.jsx", "src/app/(panels)/suite/layout.jsx", "src/app/(panels)/suite/doctor/dashboard/page.jsx", "src/app/(panels)/suite/patient/chat/page.jsx"], "exclude": ["node_modules"] }