bland-finland-95044
08/06/2024, 6:46 PMchilly-king-10285
08/06/2024, 6:46 PMchilly-king-10285
08/06/2024, 6:46 PMpowershell $Env:ORY_SDK_URL = "https://$<http://PROJECT_SLUG.projects.oryapis.com|PROJECT_SLUG.projects.oryapis.com>"
Replace $PROJECT_SLUG
with your project's slug. Then, use the Invoke-RestMethod cmdlet to send a request to the API. For example, to create a new user account, you can use the following command: powershell Invoke-RestMethod -Uri "$Env:ORY_SDK_URL/admin/identities" -Method Post -Headers @{"Authorization" = "Bearer $API_KEY"; "Content-Type" = "application/json"} -Body '{"schema_id": "<preset://email>", "traits": { "email": "$USER_EMAIL_ADDRESS" }}'
Replace $API_KEY
with your API key and $USER_EMAIL_ADDRESS
with the email address of the user you want to create. Remember, you need an API Key to call these endpoints. You can create API Keys in the Ory Console by following these steps: 1. Go to Project settings → API Keys in the [Ory Console](https://console.ory.sh/projects/current/developers). 2. Click Create new API key 3. Enter the API Key name and click Create 4. Copy the created API Key The API Key you created is displayed only once. When you close the prompt, you can't access the key again. Make sure to save the API Key before you close the prompt or reload the page. Sources: - [Setting up environment variables](https://www.ory.sh/docs/getting-started/integrate-auth/expressjs#run-your-expressjs-app) - [Creating a new user account](https://www.ory.sh/docs/kratos/manage-identities/invite-users#procedure) - [Creating API Keys](https://www.ory.sh/docs/concepts/personal-access-token#authorizing-ory-network-project-admin-apis)bland-finland-95044
08/06/2024, 6:53 PMchilly-king-10285
08/06/2024, 6:53 PMchilly-king-10285
08/06/2024, 6:54 PMGET /admin/identities
endpoint to list all identities in the system. Here is an example of how to use this endpoint with curl: bash curl -X GET "<https://your-ory-instance.com/admin/identities>"
Replace <https://your-ory-instance.com>
with the URL of your Ory instance. Using the CLI: You can use the ory list identities
or kratos list identities
command to list all identities. Here is an example of how to use this command: bash ory list identities --page-size 100 --consistency eventual
or bash kratos list identities --page-size 100 --consistency eventual
This command will return a list of identities. The --page-size
option specifies the maximum number of items to return, and the --consistency
option specifies the read consistency to use. Sources: - [Ory API Reference](https://www.ory.sh/docs/reference/api) - [Kratos API Reference](https://www.ory.sh/docs/kratos/reference/api) - [Ory CLI Documentation](https://www.ory.sh/docs/cli/ory-list-identities#ory-list-identities) - [Kratos CLI Documentation](https://www.ory.sh/docs/kratos/cli/kratos-list-identities#kratos-list-identities)bland-finland-95044
08/13/2024, 4:59 PMchilly-king-10285
08/13/2024, 4:59 PMchilly-king-10285
08/13/2024, 4:59 PMtoSession()
method. If the user's session is no longer active, the toSession()
method will throw an error, which you can catch and handle accordingly. Here is an example of how you can do this: jsx import { Configuration, FrontendApi, Session } from "@ory/client" import { useEffect, useState } from "react" import { useRouter } from "next/router" const ory = new FrontendApi(new Configuration(edgeConfig)) export default function Home() { const router = useRouter() const [session, setSession] = useState<Session | undefined>() useEffect(() => { ory .toSession() .then(({ data }) => { // User has a session! setSession(data) }) .catch(() => { // Redirect to login page return router.push(edgeConfig.basePath + "/ui/login") }) }, [router]) if (!session) { // Still loading return null } // Rest of your component }
In this example, the useEffect
hook is used to call the toSession()
method when the component mounts. If the user has an active session, the session data is stored in the session
state variable. If the user does not have an active session, the user is redirected to the login page. Please note that you need to replace edgeConfig
with your actual configuration. Source: [Getting-started > Integrate-auth > Integrate authentication into Next.js > Create Next.js app > Require login to access the home page Part 1](https://www.ory.sh/docs/getting-started/integrate-auth/nextjs#require-login-to-access-the-home-page)