{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "quickstart-with-custom-auth",
  "title": "Quickstart for Next js with server side authentication",
  "description": "A quickstart for next.js Sitecore marketplace apps with server side authentication",
  "dependencies": [
    "@auth0/auth0-react"
  ],
  "registryDependencies": [
    "https://blok.sitecore.com/r/marketplace/next/quickstart.json"
  ],
  "files": [
    {
      "path": "src/marketplace/next/components/providers/auth.tsx",
      "content": "\"use client\";\n\nimport {\n  type Auth0ContextInterface,\n  Auth0Provider,\n  type GetTokenSilentlyOptions,\n  useAuth0,\n  withAuthenticationRequired,\n} from \"@auth0/auth0-react\";\nimport type React from \"react\";\n\nexport const WithAuth = withAuthenticationRequired(\n  ({ children }: { children: React.ReactNode }) => children,\n);\n\nexport const AuthProvider = ({ children }: { children: React.ReactNode }) => {\n  const authParams = {\n    organization_id: process.env.NEXT_PUBLIC_SITECORE_ORGANIZATION_ID,\n    tenant_id: process.env.NEXT_PUBLIC_SITECORE_TENANT_ID,\n    product_codes: `mkp_${process.env.NEXT_PUBLIC_SITECORE_APP_ID}`,\n    audience: process.env.NEXT_PUBLIC_AUTH0_AUDIENCE,\n    redirect_uri: process.env.NEXT_PUBLIC_APP_BASE_URL,\n    scope: process.env.NEXT_PUBLIC_AUTH0_SCOPE,\n  };\n\n  const domain = process.env.NEXT_PUBLIC_AUTH0_DOMAIN;\n  const clientId = process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID;\n\n  if (!domain || !clientId) {\n    throw new Error(\"Auth0 domain and client ID are required\");\n  }\n\n  return (\n    <Auth0Provider\n      domain={domain}\n      clientId={clientId}\n      authorizationParams={{\n        ...authParams,\n      }}\n    >\n      <WithAuth>{children}</WithAuth>\n    </Auth0Provider>\n  );\n};\n\nexport const useAuth = (): Auth0ContextInterface => {\n  const { getAccessTokenSilently, ...rest } = useAuth0();\n\n  const customGetAccessTokenSilently = (options?: GetTokenSilentlyOptions) => {\n    return getAccessTokenSilently({\n      ...options,\n      authorizationParams: {\n        ...options?.authorizationParams,\n        organization_id: process.env.NEXT_PUBLIC_SITECORE_ORGANIZATION_ID,\n        tenant_id: process.env.NEXT_PUBLIC_SITECORE_TENANT_ID,\n      },\n    });\n  };\n\n  return {\n    ...rest,\n    getAccessTokenSilently:\n      customGetAccessTokenSilently as Auth0ContextInterface[\"getAccessTokenSilently\"],\n  };\n};\n",
      "type": "registry:component",
      "target": "components/providers/auth.tsx"
    },
    {
      "path": "src/marketplace/next/layouts/with-auth.tsx",
      "content": "import type { Metadata } from \"next\";\nimport { Geist, Geist_Mono } from \"next/font/google\";\nimport \"./globals.css\";\nimport { AuthProvider } from \"@/components/providers/auth\";\nimport { MarketplaceProvider } from \"@/components/providers/marketplace\";\n\nconst geistSans = Geist({\n  variable: \"--font-geist-sans\",\n  subsets: [\"latin\"],\n});\n\nconst geistMono = Geist_Mono({\n  variable: \"--font-geist-mono\",\n  subsets: [\"latin\"],\n});\n\nexport const metadata: Metadata = {\n  title: \"Create Next App\",\n  description: \"Generated by create next app\",\n};\n\nexport default function RootLayout({\n  children,\n}: Readonly<{\n  children: React.ReactNode;\n}>) {\n  return (\n    <html lang=\"en\">\n      <body\n        className={`${geistSans.variable} ${geistMono.variable} antialiased`}\n      >\n        <AuthProvider>\n          <MarketplaceProvider>{children}</MarketplaceProvider>\n        </AuthProvider>\n      </body>\n    </html>\n  );\n}\n",
      "type": "registry:file",
      "target": "app/layout.tsx"
    },
    {
      "path": "src/marketplace/next/next.config.ts",
      "content": "import type { NextConfig } from \"next\";\n\nconst nextConfig: NextConfig = {\n  async headers() {\n    const allowedParentDomains = [\n      \"https://marketplace-app.sitecorecloud.io\",\n      \"https://pages.sitecorecloud.io\",\n      \"https://xmapps.sitecorecloud.io\",\n    ];\n\n    return [\n      {\n        source: \"/(.*)\",\n        headers: [\n          {\n            key: \"Content-Security-Policy\",\n            value: `frame-ancestors 'self' ${allowedParentDomains.join(\" \")}`,\n          },\n        ],\n      },\n    ];\n  },\n};\n\nexport default nextConfig;\n",
      "type": "registry:file",
      "target": "next.config.ts"
    }
  ],
  "envVars": {
    "NEXT_PUBLIC_AUTH0_DOMAIN": "https://auth.sitecorecloud.io",
    "NEXT_PUBLIC_AUTH0_AUDIENCE": "https://api-webapp.sitecorecloud.io",
    "NEXT_PUBLIC_AUTH0_SCOPE": "openid profile email offline_access",
    "NEXT_PUBLIC_AUTH0_CLIENT_ID": "your-marketplace-client-id",
    "NEXT_PUBLIC_SITECORE_APP_ID": "your-app-id",
    "NEXT_PUBLIC_APP_BASE_URL": "https://localhost:3000",
    "NEXT_PUBLIC_SITECORE_ORGANIZATION_ID": "your-organization-id",
    "NEXT_PUBLIC_SITECORE_TENANT_ID": "marketplace-app-tenant-id-after-installation"
  },
  "docs": "Your app needs to run in 'https'. We suggest to add '--experimental-https' in your dev script in package.json. Also, make sure to update your environment variables. Happy coding!",
  "type": "registry:block"
}