// React import { useCallback, useEffect, useState } from "react" // Next.js import Router from "next/router" // Ory SDK import { ory } from "@/pkg/sdk" // Import CSS import styles from "../styles/Dashboard.module.css" // Misc. import { AxiosError } from "axios" // We will use CodeBox from Ory Elements to display the session information. import Layout from "@/components/layout" import { Session } from "@ory/client" import { CodeBox } from "@ory/elements" import { HandleError } from "@/pkg/hooks" import { NextPageWithLayout } from "./_app" const Home: NextPageWithLayout = () => { const [session, setSession] = useState() const handleError = useCallback((error: AxiosError) => { const handle = HandleError(undefined, undefined, "/login") return handle(error) }, []) useEffect(() => { // If the router is not ready yet, or we already have a session, do nothing. ory .toSession() .then(({ data: session }) => { // we set the session data which contains the user Identifier and other traits. setSession(session) }) .catch(handleError) .catch((error) => { // Handle all other errors like error.message "network error" if Kratos can not be connected etc. if (error.message) { return Router.push( `/error?error=${encodeURIComponent(error.message)}`, ) } // Just stringify error and print all data return Router.push( `/error?error=${encodeURIComponent(JSON.stringify(error))}`, ) }) }, [handleError]) return session ? (

Welcome to{" "} Next.js {" "} with{" "} Ory Elements

Session Information

{/* Displays the current session information */} {JSON.stringify(session, null, 2)}
) : (
Loading...
) } Home.getLayout = (page) => {page} export default Home