import { SessionProvider } from 'next-auth/react'
import Auth from '../components/auth'
import User from '../components/user'

// This is the HOC
function withAuth(WrappedComponent) {
  // Return a new component
  function withAuth({ session, ...pageProps }) {
    // Render the WrappedComponent with additional props
    return (
      <SessionProvider session={session}>
        <Auth>
          <User />
          <WrappedComponent {...pageProps} />
        </Auth>
      </SessionProvider>
    )
  }

  withAuth.displayName = `withAuth(${WrappedComponent.displayName}`

  return withAuth
}

export default withAuth
