refined-fall-81170
05/17/2024, 4:57 PMchilly-king-10285
05/17/2024, 4:57 PMchilly-king-10285
05/17/2024, 4:57 PMSet-Cookie
header is set which contains the Ory Session Cookie. This cookie is named ory_kratos_session
. You can use this session cookie to authenticate subsequent requests in your web application. For example, when making a request to the /sessions/whoami
endpoint, the session will be returned if the browser sends the request with the session cookie. Here is an example of how you can check the current session in a React application: javascript import { Configuration, FrontendApi, Session } from "@ory/client" import { useEffect, useState } from "react" const frontend = new FrontendApi( new Configuration({ basePath: "<http://localhost:4000>", // Use your local Ory Tunnel URL baseOptions: { withCredentials: true, }, }), ) export function checkSession() { const [session, setSession] = useState<Session>(undefined) useEffect(() => { frontend // the cookie is automatically sent with the request .toSession() .then(({ data: session }) => { setSession(session) }) .catch((error) => { // The session could not be fetched // This might occur if the current session has expired }) }, []) return session ? ( <table> <tr> <th>Session ID</th> <th>Expires at</th> <th>Authenticated at</th> </tr> <tr id={session.id}> <td>{session.id}</td> <td>{session.expires_at || ""}</td> <td>{session.authenticated_at || ""}</td> </tr> </table> ) : ( <div>Loading session data...</div> ) }
For more information, you can refer to the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-login#successful-login) and [Ory Session Cookie usage](https://www.ory.sh/docs/kratos/session-management/overview#using-ory-session-cookie).