<@U04UQ68083H> does ory ts client support validati...
# ory-copilot
a
@chilly-king-10285 does ory ts client support validating tokenized session?
b
A message from kapa.ai
Yes, the Ory TypeScript client supports validating tokenized sessions. When using the Ory SDK, you can validate sessions in several ways: 1. For browser-based applications, you can validate sessions using cookies:
Copy code
typescript 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       })   }, [])      // Use session data here }
2. For native applications, you can validate sessions using session tokens:
Copy code
typescript import { Configuration, FrontendApi } from "@ory/client"  const frontend = new FrontendApi(   new Configuration({     basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`,   }), )  export async function checkSession(sessionId: string, token: string) {   return await frontend.toSession({     xSessionToken: token,   }) }
3. You can also request a tokenized version of the session (like a JWT) by using the
tokenize_as
parameter:
Copy code
typescript // When using a token template, the token is included in the `tokenized` field of the session const session = await client.toSession("the-session-token", { tokenize_as: "example-jwt-template" }) console.log(session.tokenized) // The JWT
The tokenized field in the session response will contain the JWT that you can then use for validation purposes. [Ory Session Management Overview](https://www.ory.sh/docs/kratos/session-management/overview) [Ory API Reference](https://www.ory.sh/docs/reference/api) [Ory Proxy with JSON Web Tokens](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel#use-ory-proxy-with-json-web-tokens)