11import { useEffect , useState } from "react" ;
2- import { useAuth } from "../App/AuthContext " ;
2+ import { authClient } from "../lib/auth-client " ;
33import FunctionCard from "../components/ui/FunctionCard" ;
44import axios from "axios" ;
55import { Blocks } from "react-loader-spinner" ;
@@ -19,23 +19,23 @@ function Dashboard()
1919 // each user starts with a userFunction array of size 0
2020 const [ userFunctions , setUserFunctions ] = useState < userFunction [ ] > ( [ ] ) ;
2121
22- const { session, isPending } = useAuth ( ) ;
22+ const session = authClient . useSession ( ) ;
2323
2424 const navigate = useNavigate ( )
2525
2626 const serverUrl = import . meta. env . VITE_SERVER_URL || 'http://localhost:3000'
2727
2828 useEffect ( ( ) => {
2929 // user is not logged in
30- if ( ! isPending && ! session ) {
30+ if ( ! session . isPending && ! session . data ?. session ) {
3131 navigate ( "/sign-in" , { replace : true } )
3232 return
3333 }
3434
3535 if ( session ) {
3636 getFuncs ( ) ;
3737 }
38- } , [ isPending ] ) ;
38+ } , [ session . isPending ] ) ;
3939
4040 // show loading while checking if user is logged in
4141 if ( ! session ) {
@@ -46,7 +46,7 @@ function Dashboard()
4646 }
4747
4848 const getFuncs = async ( ) => {
49- const userId = session . user . id ;
49+ const userId = session . data ?. user . id ;
5050 try {
5151 const response = await axios . get ( serverUrl + `/func/all/${ userId } ` ) ;
5252 setUserFunctions ( response . data ) ;
@@ -72,7 +72,7 @@ function Dashboard()
7272
7373 return (
7474 < div >
75- < h2 className = "mb-5 ml-[20px]" > { session . user . name } 's Dashboard</ h2 >
75+ < h2 className = "mb-5 ml-[20px]" > { session . data ?. user . name } 's Dashboard</ h2 >
7676
7777 { userFunctions . length > 0 ?
7878 < div className = "dashboard" >
0 commit comments