taxonomy/lib/session.ts

16 lines
363 B
TypeScript
Raw Permalink Normal View History

2022-10-26 13:18:06 +00:00
import { Session } from "next-auth"
export async function getSession(cookie: string): Promise<Session> {
2022-10-28 07:43:38 +00:00
const response = await fetch(`${process.env.NEXTAUTH_URL}/api/auth/session`, {
2022-10-26 13:18:06 +00:00
headers: { cookie },
})
if (!response?.ok) {
return null
}
const session = await response.json()
return Object.keys(session).length > 0 ? session : null
}