import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
import React from 'react'

const Authenticated = ({ children }: { children: React.ReactNode }) => {
  const credentialStr = cookies().get('credential')?.value
  const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null

  if (!credential) redirect('/login')

  return children
}

export default Authenticated