few-napkin-57613
07/10/2024, 3:29 AMchilly-king-10285
07/10/2024, 3:29 AMchilly-king-10285
07/10/2024, 3:30 AMbash npm i --save @ory/integrations @ory/client
2. Creating a special route in [...paths].js
at pages/api/.ory/
that connects your Next.js app with Ory's APIs. This ensures that all cookies and credentials are set up. Without it, your Next.js application won't be able to talk to Ory's APIs. 3. Setting up your environment variables to connect with Ory's APIs and starting the Next.js development server: bash export NEXT_PUBLIC_ORY_SDK_URL=https://$<http://PROJECT_SLUG.projects.oryapis.com|PROJECT_SLUG.projects.oryapis.com> npm run dev
4. When upgrading to production, you need to set up a custom domain and configure your Next.js app to use it. Once you have configured a custom domain and deployed your application the integrations package is no longer needed. Please refer to the [Ory documentation](https://www.ory.sh/docs/getting-started/integrate-auth/nextjs) for more detailed instructions and examples. For Next.js 14 and app router specific integration, I would recommend checking the official Next.js and Ory Kratos documentation or forums for the most up-to-date information.few-napkin-57613
07/10/2024, 3:31 AMchilly-king-10285
07/10/2024, 3:31 AMchilly-king-10285
07/10/2024, 3:31 AMjavascript import { Configuration, FrontendApi, Session, Identity } from "@ory/client" import { edgeConfig } from "@ory/integrations/next"
2. Then, create a new instance of the FrontendApi: javascript const ory = new FrontendApi(new Configuration(edgeConfig))
3. In your server component, you can use the toSession()
method to get the current user's session: javascript ory.toSession().then(({ data }) => { // User has a session! setSession(data) })
4. The data
object now contains the user's session data, which includes their identity. You can access specific user data like this: javascript const getUserName = (identity: Identity) => identity.traits.email || identity.traits.username
This function will return either the user's email or username, depending on their Identity Schema. Please note that this is a general approach and might need adjustments based on your specific setup and requirements. For more detailed information, please refer to the [Ory documentation](https://www.ory.sh/docs/getting-started/integrate-auth/nextjs#require-login-to-access-the-home-page).