<@U04UQ68083H>, is there a next.js sample code for...
# ory-copilot
b
@chilly-king-10285, is there a next.js sample code for frontend implementation for the latest sdk
c
A message from kapa.ai
Yes, there is a Next.js sample code for frontend implementation with the latest SDK. Here's how you can set it up: 1. First, create a new Next.js project:
Copy code
bash npx create-next-app@latest --typescript   cd <your-project-directory>
2. Set up your environment variables to connect with Ory's APIs:
Copy code
bash export NEXT_PUBLIC_ORY_SDK_URL=https://$<http://PROJECT_SLUG.projects.oryapis.com|PROJECT_SLUG.projects.oryapis.com>
3. Start the Next.js development server:
Copy code
bash npm run dev
4. Add a session check to the default home page of the Next.js example application to check whether the user is signed in, and redirect them to the login page if not:
Copy code
javascript import { Configuration, FrontendApi, Session, Identity } from "@ory/client"   import { edgeConfig } from "@ory/integrations/next"    const ory = new FrontendApi(new Configuration(edgeConfig))    const getUserName = (identity: Identity) =>     identity.traits.email || identity.traits.username    const Home = () => {     const router = useRouter()     const [session, setSession] = useState<Session | undefined>()     const [logoutUrl, setLogoutUrl] = useState<string | undefined>()      useEffect(() => {       ory         .toSession()         .then(({ data }) => {           setSession(data)           ory.createBrowserLogoutFlow().then(({ data }) => {             setLogoutUrl(data.logout_url)           })         })         .catch(() => {           return router.push(edgeConfig.basePath + "/ui/login")         })     }, [router])      if (!session) {       return null     }      // Rest of your component }
You can find more details in the [Ory documentation](https://www.ory.sh/docs/getting-started/integrate-auth/nextjs). When upgrading to production, you need to set up a custom domain and configure your Next.js app to use it. You can find more details on how to do this in the [Ory documentation](https://www.ory.sh/docs/getting-started/integrate-auth/nextjs#go-to-production).
b
@chilly-king-10285 is there a sample login page?
c
A message from kapa.ai
Yes, there are several examples of login pages provided in the Ory documentation. Here are a few: 1. Next.js/React: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Next.js/React. 2. Express.js: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Express.js. 3. Go: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Go. 4. PHP: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using PHP. 5. Vue.js: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Vue.js. 6. Flutter: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Flutter. 7. Django: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Django. 8. Flask: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using Flask. 9. .NET Core: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using .NET Core. 10. ASP.NET Core: This [example](https://www.ory.sh/docs/getting-started/overview) shows how to protect a page with login using ASP.NET Core. You can find more examples and tutorials in the [Ory documentation](https://www.ory.sh/docs/getting-started/overview).