{"id":15371277,"url":"https://github.com/sandrinodimattia/nextjs-auth0-example","last_synced_at":"2025-09-17T11:20:29.768Z","repository":{"id":40934407,"uuid":"207877287","full_name":"sandrinodimattia/nextjs-auth0-example","owner":"sandrinodimattia","description":"A sample application showing how your users can sign in to your Next.js application using Auth0","archived":false,"fork":false,"pushed_at":"2023-01-04T22:00:32.000Z","size":778,"stargazers_count":44,"open_issues_count":17,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T14:07:53.293Z","etag":null,"topics":["auth0","nextjs"],"latest_commit_sha":null,"homepage":"https://nextjs-auth0-demo.now.sh/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandrinodimattia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-11T18:15:05.000Z","updated_at":"2024-10-14T07:34:48.000Z","dependencies_parsed_at":"2023-02-02T21:15:14.233Z","dependency_job_id":null,"html_url":"https://github.com/sandrinodimattia/nextjs-auth0-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sandrinodimattia/nextjs-auth0-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrinodimattia%2Fnextjs-auth0-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrinodimattia%2Fnextjs-auth0-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrinodimattia%2Fnextjs-auth0-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrinodimattia%2Fnextjs-auth0-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandrinodimattia","download_url":"https://codeload.github.com/sandrinodimattia/nextjs-auth0-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrinodimattia%2Fnextjs-auth0-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275583874,"owners_count":25490781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth0","nextjs"],"created_at":"2024-10-01T13:46:16.325Z","updated_at":"2025-09-17T11:20:29.745Z","avatar_url":"https://github.com/sandrinodimattia.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js and Auth0 Example\n\nThis example shows how you can use [`@auth0/nextjs-auth0`](https://github.com/auth0/nextjs-auth0) to easily add authentication support to your Next.js application.\n\n## Configuring Auth0\n\nGo to the [Auth0 dashboard](https://manage.auth0.com/) and create a new application of type *Web Application* and make sure to configure the following:\n\n - *Allowed Callback URLs*: Should be set to `http://localhost:3000/api/callback` when testing locally or typically to `https://myapp.com/api/callback` when deploying your application.\n - *Allowed Logout URLs*: Should be set to `http://localhost:3000/` when testing locally or typically to `https://myapp.com/` when deploying your application.\n\n### Configuring Next.js\n\nIn the Next.js configuration file (`next.config.js`) you'll see that different environment variables are being loaded in the server runtime configuration. \n\n### Local Development\n\nFor local development you'll just want to create a `.env` file with the necessary settings:\n\n```\nAUTH0_DOMAIN=YOUR_AUTH0_DOMAIN\nAUTH0_CLIENT_ID=YOUR_AUTH0_CLIENT_ID\nAUTH0_CLIENT_SECRET=YOUR_AUTH0_CLIENT_SECRET\nREDIRECT_URI=http://localhost:3000/api/callback\nPOST_LOGOUT_REDIRECT_URI=http://localhost:3000/\nSESSION_COOKIE_SECRET=viloxyf_z2GW6K4CT-KQD_MoLEA2wqv5jWuq4Jd0P7ymgG5GJGMpvMneXZzhK3sL (at least 32 characters, used to encrypt the cookie)\n```\n\n### Hosting in Now.sh\n\nWhen deploying this example to Now.sh you'll want to update the `now.json` configuration file:\n\n```json\n{\n  \"build\": {\n    \"env\": {\n      \"AUTH0_DOMAIN\": \"YOUR_AUTH0_DOMAIN\",\n      \"AUTH0_CLIENT_ID\": \"YOUR_AUTH0_CLIENT_ID\",\n      \"AUTH0_CLIENT_SECRET\": \"@auth0_client_secret\",\n      \"REDIRECT_URI\": \"https://my-website.now.sh/api/callback\",\n      \"POST_LOGOUT_REDIRECT_URI\": \"https://my-website.now.sh/\",\n      \"SESSION_COOKIE_SECRET\": \"@session_cookie_secret\",\n      \"SESSION_COOKIE_LIFETIME\": 7200\n    }\n  }\n}\n```\n\nSome of these values are settings and can just be added to your repository if you want. Others are actual secrets and need to be created as such using the `now` CLI:\n\n```bash\nnow secrets add auth0_client_secret YOUR_AUTH0_CLIENT_SECRET\nnow secrets add session_cookie_secret viloxyf_z2GW6K4CT-KQD_MoLEA2wqv5jWuq4Jd0P7ymgG5GJGMpvMneXZzhK3sL\n```\n\n## About this sample\n\nThis sample tries to cover a few topics:\n\n - Signing in\n - Signing out\n - Registration\n - Loading the user on the server side and adding it as part of SSR (`/pages/profile.js`)\n - Loading the user on the client side and using fast/cached SSR pages (`/pages/index.js`)\n - API Routes which can load the current user (`/pages/api/me.js`)\n - Using hooks to make the user available throughout the application (`/lib//user.js`)\n\n## Scenarios\n\n### User Registration\n\nWhen the user is not signed in you'll see a Register and a Login link:\n\n```js\n\u003cli\u003e\n  \u003ca href='/api/register'\u003eRegister\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003e\n  \u003ca href='/api/login'\u003eLogin\u003c/a\u003e\n\u003c/li\u003e\n```\n\nThe Register link redirects to the `/api/register` API route calling the login handler and passing a custom parameter which sets `prompt=signup`.\n\n```js\nimport auth0 from '../../lib/auth0';\n\nexport default async function register(req, res) {\n  try {\n    await auth0.handleLogin(req, res, {\n      authParams: {\n        initialScreen: 'signup'\n      }\n    });\n  } catch(error) {\n    console.error(error)\n    res.status(error.status || 500).end(error.message)\n  }\n}\n```\n\nThis parameter is then exposed to the Auth0 login page which can be used to show the signup tab. Note that this only works for the \"Classic\" experience today. In order to change to the signup tab when this parameter is sent, you'll need to modify the Login page in Auth0 and add the `initialScreen`:\n\n```js\nvar lock = new Auth0Lock(config.clientID, config.auth0Domain, {\n  ...\n  initialScreen: (config.extraParams.initialScreen === 'signup' \u0026\u0026 'signUp') || 'login',\n  ...\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandrinodimattia%2Fnextjs-auth0-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandrinodimattia%2Fnextjs-auth0-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandrinodimattia%2Fnextjs-auth0-example/lists"}