<div></div>

<script>
import { makeLogtoClient } from "../utils/auth"

const callbackHandler = async (logtoClient) => {
  console.log("callbackHandler")
  try {
    await logtoClient.handleSignInCallback(window.location.href)
    if (!logtoClient.isAuthenticated) {
      console.log("User not authenticated")
      window.location.assign("/")
      return
    }
  }
  catch (error) {
    console.log(error)
    window.location.assign("/")
  }
}

console.log("Callback page loaded")
try {
  const logtoClient = makeLogtoClient()
  callbackHandler(logtoClient)
}
catch (error) {
  console.log(error)
}
</script>
