18 lines
378 B
TypeScript
18 lines
378 B
TypeScript
|
import { db } from "@/lib/db"
|
||
|
import { useSession } from "next-auth/react"
|
||
|
|
||
|
export const currentUser = async() => {
|
||
|
const { data: session, status } = useSession()
|
||
|
|
||
|
if (status !== "authenticated") {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
const user = await db.user.findUnique({
|
||
|
where: {
|
||
|
id: session?.user?.name as string
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return user;
|
||
|
}
|