{"id":26269813,"url":"https://github.com/m4rc0sx/nextjs-nextauth-fastapi-oauth-example","last_synced_at":"2026-05-06T17:35:28.210Z","repository":{"id":246697762,"uuid":"821775180","full_name":"M4RC0Sx/NextJS-NextAuth-FastAPI-OAuth-Example","owner":"M4RC0Sx","description":"NextJS + AuthJS/NextAuth + FastAPI (custom backend) OAuth authentication example.","archived":false,"fork":false,"pushed_at":"2024-06-29T18:25:14.000Z","size":103,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-01T16:56:13.993Z","etag":null,"topics":["approuter","auth","authjs","custombackend","fastapi","next13","next14","nextauth","nextjs","oauth"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/M4RC0Sx.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-29T11:56:24.000Z","updated_at":"2025-01-25T11:39:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"48b5c8f6-f912-47ee-940a-15d0b86178f9","html_url":"https://github.com/M4RC0Sx/NextJS-NextAuth-FastAPI-OAuth-Example","commit_stats":null,"previous_names":["m4rc0sx/nextjs-nextauth-fastapi-oauth-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/M4RC0Sx/NextJS-NextAuth-FastAPI-OAuth-Example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4RC0Sx%2FNextJS-NextAuth-FastAPI-OAuth-Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4RC0Sx%2FNextJS-NextAuth-FastAPI-OAuth-Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4RC0Sx%2FNextJS-NextAuth-FastAPI-OAuth-Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4RC0Sx%2FNextJS-NextAuth-FastAPI-OAuth-Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/M4RC0Sx","download_url":"https://codeload.github.com/M4RC0Sx/NextJS-NextAuth-FastAPI-OAuth-Example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4RC0Sx%2FNextJS-NextAuth-FastAPI-OAuth-Example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32704653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T08:33:17.875Z","status":"ssl_error","status_checked_at":"2026-05-06T08:33:17.221Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["approuter","auth","authjs","custombackend","fastapi","next13","next14","nextauth","nextjs","oauth"],"created_at":"2025-03-14T05:16:09.550Z","updated_at":"2026-05-06T17:35:28.188Z","avatar_url":"https://github.com/M4RC0Sx.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NextJS-NextAuth-FastAPI-OAuth-Example\n\nThis is an example project that shows how to connect a frontend made with NextJS14 (app router) with a backend in FastAPI, using an OAuth authentication with GitHub as provider.\n\n\n## Tech stack:\n- Python 3.12.4 with FastAPI for the backend. \n- Poetry as Python dependency manager.\n- Ruff as Python formatter.\n- NodeJS 20.15.0 for the frontend.\n- NPM as Node dependency manager.\n- ESLint + Prettier (eslint-config-prettier) for linting and code formatting.\n- NextAuth (AuthJS) for auth management in the frontend.\n\n## DISCLAIMER\n- There is no information persistence of any kind.\n- This project is not production-ready.\n- The frontend is the ugliest thing you're going to see today. I haven't styled any component.\n- This project is only a proof of concept, so it does not meet all the standards of good development practices.\n- A monorepo structure has been used to speed up the access to the files and to have everything in the same place. In a real project, having backend and frontend in the same repository is not usually the most convenient...\n\n## TO-DO list\n- Implement user persistence in the API.\n- Add more providers.\n- Consider a possible caching or token checking in the backend to avoid the rate-limit of the providers in case of too many requests. Could do a custom implementation of Python's LRU cache, adding timeout: (https://docs.python.org/3/library/functools.html#functools.lru_cache)\n- Structure the FastAPI project correctly.\n\n## How does it work?\n1. On the frontend, NextAuth controls the authentication flow with providers. In this case, GitHub.\n2. Once authenticated, it generates a session and includes in this session the provider used and the access token returned by the API of this provider.\n3. When a request is sent to the backend from the frontend, this provider and its API access token are included in the header.\n4. In the backend, a request is made to the API of the corresponding provider to check that the token is valid.\n\n## How to run the project?\n1. Clone the repository.\n```bash\ngit clone https://github.com/M4RC0Sx/NextJS-NextAuth-FastAPI-OAuth-Example.git\n```\n\n2. Install the Python dependencies with Poetry. It is recommended to have PyEnv installed for managing multiple Python versions.\n```bash\ncd backend\npyenv local 3.12.4\npoetry install\n```\n\n3. Start the backend, it will be available at http://localhost:8000.\n```bash\npoetry run uvicorn main:app --reload\n```\n\n4. Access the frontend directory and install the Node dependencies. It is recommended to use NVM for managing multiple versions of Node.\n```bash\ncd ..\ncd frontend\nnvm install --lts\nnvm use --lts\nnpm install\n```\n\n5. Create an OAuth application in the GitHub Developer Settings portal (when creating the app on the GitHub portal, use this URL as the authorization callback URL: http://localhost:3000/api/auth/callback/github) and populate an .env.local file with these fields:\n```\nAUTH_SECRET=RANDOM_SECRET_USED_BY_NEXTAUTH\nAUTH_GITHUB_ID=YOUR_GITHUB_OAUTH_APP_ID\nAUTH_GITHUB_SECRET=YOUR_GITHUB_OAUTH_APP_SECRET\n\n```\n\n6. Start the frontend. It will be available at https://localhost:3000.\n```bash\ncd ..\ncd frontend\nnvm install --lts\nnvm use --lts\nnpm install\n```\n\n7. Access the frontend (http://localhost:3000) and click the button to log in with GitHub. Once logged in, a button will appear to launch a sample API request.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4rc0sx%2Fnextjs-nextauth-fastapi-oauth-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm4rc0sx%2Fnextjs-nextauth-fastapi-oauth-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4rc0sx%2Fnextjs-nextauth-fastapi-oauth-example/lists"}