limited-city-59768
02/06/2024, 9:02 AMchilly-king-10285
02/06/2024, 9:02 AMchilly-king-10285
02/06/2024, 9:02 AMtoSession
endpoint. This endpoint authenticates users by checking if the Cookie
HTTP header was set containing an Ory Kratos Session Cookie, if the Authorization: bearer <ory-session-token>
HTTP header was set with a valid Ory Kratos Session Token, or if the X-Session-Token
HTTP header was set with a valid Ory Kratos Session Token. If none of these headers are set or the cookie or token are invalid, the endpoint returns a HTTP 401 status code. Another endpoint is <http://127.0.0.1/sessions/whoami>
. This endpoint can be used to check the Ory Session Token. For more details, you can refer to the [Ory API Reference](https://www.ory.sh/docs/reference/api) and [Kratos API Reference](https://www.ory.sh/docs/kratos/reference/api).limited-city-59768
02/06/2024, 9:17 AMchilly-king-10285
02/06/2024, 9:17 AMchilly-king-10285
02/06/2024, 9:18 AM/sessions/whoami
endpoint while automatically including the cookies in the request. This will return the session data. Here is an example of how to use the SDK to get the session: tsx 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 details, you can refer to the [Ory Documentation](https://www.ory.sh/docs/kratos/self-service/flows/verify-email-account-activation#choosing-the-right-strategy) and [Ory API Reference](https://www.ory.sh/docs/reference/api).limited-city-59768
02/06/2024, 9:21 AMchilly-king-10285
02/06/2024, 9:21 AMchilly-king-10285
02/06/2024, 9:21 AM/sessions/whoami
endpoint. If the user doesn't have an active session, the system returns a 401 Unauthorized
response. If the user has an active session, you get a 200 OK
response and the session payload. For more details, you can refer to the [Ory Documentation](https://www.ory.sh/docs/kratos/session-management/overview) and [Ory API Reference](https://www.ory.sh/docs/reference/api).