{"id":50746984,"url":"https://github.com/zitadel/elysia-auth","last_synced_at":"2026-06-10T22:01:41.522Z","repository":{"id":359980026,"uuid":"1223583783","full_name":"zitadel/elysia-auth","owner":"zitadel","description":"Official Zitadel auth integration for Elysia.","archived":false,"fork":false,"pushed_at":"2026-06-09T07:56:28.000Z","size":646,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-09T09:28:02.698Z","etag":null,"topics":["auth","authentication","authn","authorization","authz","elysia","iam","identity","login","nodejs","sso","typescript","zitadel"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@zitadel/elysia-auth","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zitadel.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-28T13:11:22.000Z","updated_at":"2026-06-08T13:44:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zitadel/elysia-auth","commit_stats":null,"previous_names":["zitadel/elysia-auth"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zitadel/elysia-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Felysia-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Felysia-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Felysia-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Felysia-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zitadel","download_url":"https://codeload.github.com/zitadel/elysia-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Felysia-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34172196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"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":["auth","authentication","authn","authorization","authz","elysia","iam","identity","login","nodejs","sso","typescript","zitadel"],"created_at":"2026-06-10T22:01:40.124Z","updated_at":"2026-06-10T22:01:41.508Z","avatar_url":"https://github.com/zitadel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elysia Auth.js\n\nAn [Elysia](https://elysiajs.com/) integration for [Auth.js](https://authjs.dev/)\nthat provides seamless authentication with multiple providers, session\nmanagement, and route protection using Elysia plugin patterns.\n\nThis integration brings the power and flexibility of Auth.js to Elysia\napplications with full TypeScript support and Web API-native handling.\n\n### Why?\n\nModern web applications require robust, secure, and flexible authentication\nsystems. While Auth.js provides excellent authentication capabilities,\nintegrating it with Elysia applications requires proper plugin composition\nand environment-aware configuration.\n\nHowever, a direct integration isn't always straightforward. Different types\nof applications or deployment scenarios might warrant different approaches:\n\n- **Plugin Composition:** Elysia's plugin pattern requires proper decorator\n  management and lifecycle hook handling. This integration provides plugins\n  for configuration, authentication handling, and route protection that\n  compose naturally with Elysia's plugin pipeline.\n- **Node.js Support:** While Elysia is Bun-first, many projects use Node.js\n  via `@elysiajs/node`. This integration works seamlessly with both runtimes,\n  handling environment differences transparently while maintaining consistent\n  Auth.js behavior.\n- **Proxy-Aware URL Handling:** When deployed behind reverse proxies or\n  edge networks, proper URL resolution from X-Forwarded headers is critical\n  for Auth.js callback URLs and redirect handling.\n\nThis integration, `@zitadel/elysia-auth`, aims to provide the flexibility to\nhandle such scenarios. It allows you to leverage the full Auth.js ecosystem\nwhile maintaining Elysia best practices, ultimately leading to a more\neffective and less burdensome authentication implementation.\n\n## Installation\n\nInstall using NPM by using the following command:\n\n```sh\nnpm install @zitadel/elysia-auth @auth/core\n```\n\n## Usage\n\nTo use this integration, configure Auth.js using `initAuthConfig()` and\nmount the `authHandler()` on the Auth.js base path.\n\n```typescript\nimport { Elysia } from 'elysia';\nimport {\n  authHandler,\n  getAuthUser,\n  initAuthConfig,\n  verifyAuth,\n} from '@zitadel/elysia-auth';\nimport type { AuthConfig } from '@zitadel/elysia-auth';\nimport Zitadel from '@auth/core/providers/zitadel';\n\nconst authConfig: AuthConfig = {\n  secret: process.env.AUTH_SECRET,\n  providers: [\n    Zitadel({\n      clientId: process.env.ZITADEL_CLIENT_ID!,\n      issuer: process.env.ZITADEL_ISSUER!,\n    }),\n  ],\n};\n\nconst app = new Elysia()\n  .use(initAuthConfig(authConfig))\n  .use(authHandler())\n  .use(verifyAuth())\n  .get('/api/protected', async ({ request }) =\u003e {\n    const auth = await getAuthUser(request, authConfig);\n    return Response.json(auth);\n  })\n  .listen(3000);\n```\n\n#### Using the Authentication System\n\nThe integration provides several plugin functions:\n\n**Plugins:**\n\n- `initAuthConfig()`: Initializes Auth.js configuration via decorator\n- `authHandler()`: Handles all Auth.js routes (sign-in, sign-out, callbacks)\n- `verifyAuth()`: Requires authentication, returns 401 if not authenticated\n\n**Utility Functions:**\n\n- `getAuthUser()`: Retrieves the authenticated user from request\n- `setEnvDefaults()`: Sets environment defaults on Auth.js config\n- `reqWithEnvUrl()`: Rewrites request URL for proxy support\n\n**Basic Usage:**\n\n```typescript\nimport { getAuthUser, verifyAuth } from '@zitadel/elysia-auth';\n\n// Public route\napp.get('/api/public', () =\u003e {\n  return Response.json({ message: 'Public endpoint' });\n});\n\n// Protected route - manual check\napp.get('/api/profile', async ({ request }) =\u003e {\n  const authUser = await getAuthUser(request, authConfig);\n  if (!authUser) return new Response('Not authenticated', { status: 401 });\n  return Response.json(authUser.session);\n});\n\n// Protected route - using plugin\napp\n  .use(verifyAuth(authConfig))\n  .get('/api/admin', async ({ request }) =\u003e {\n    const auth = await getAuthUser(request, authConfig);\n    return Response.json({ user: auth?.session.user });\n  });\n```\n\n## Known Issues\n\n- **Configuration Order:** `initAuthConfig()` must be applied before\n  `authHandler()` and `verifyAuth()` in the plugin chain.\n- **Environment Variables:** `AUTH_SECRET` must be set either via\n  environment variables or in the config object. The plugin returns\n  a 500 error if it's missing.\n\n## Useful links\n\n- **[Auth.js](https://authjs.dev/):** The authentication library that this\n  integration is built upon.\n- **[Elysia](https://elysiajs.com/):** The ergonomic web framework this\n  integration is designed for.\n- **[Auth.js Providers](https://authjs.dev/getting-started/providers):**\n  Complete list of supported authentication providers.\n\n## Contributing\n\nIf you have suggestions for how this integration could be improved, or\nwant to report a bug, open an issue - we'd love all and any\ncontributions.\n\n## License\n\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitadel%2Felysia-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzitadel%2Felysia-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitadel%2Felysia-auth/lists"}