{"_id":"emdash-auth-discord","_rev":"6-b9a98ce884fcf1ad828295edcf29e6bd","name":"emdash-auth-discord","dist-tags":{"latest":"0.1.5"},"versions":{"0.0.0-stage":{"name":"emdash-auth-discord","version":"0.0.0-stage","_id":"emdash-auth-discord@0.0.0-stage","stub":true,"maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"dist":{"shasum":"5400e317370af5f2c7dce665097113df2c3eff55","tarball":"https://registry.npmjs.org/emdash-auth-discord/-/emdash-auth-discord-0.0.0-stage.tgz","fileCount":2,"integrity":"sha512-Z1KaICwjKkj2XLYILmjREJ/5LhYeHRsHzHvOOis92EsjKH/yTGvLt76i5S05f0I5m3gQFCNIl9gJfp6LGI+c+Q==","signatures":[{"sig":"MEUCIE40b7I5eFq4tpJJo6rv2U34MJhfhZl1qxZBhX55BPxRAiEAvM3dEC/h7L3wqUEMHxWeV5+rYXyp7IoIblOelxV589k=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":341},"_npmUser":{"name":"lecieletoile","email":"develop@leciel.dev"},"description":"Temporary package placeholder for staged publishing","directories":{}},"0.1.0":{"name":"emdash-auth-discord","version":"0.1.0","keywords":["emdash","emdash-plugin","discord","oauth","oauth2","auth","authentication","login"],"author":{"name":"leCielEtoile"},"license":"MIT","_id":"emdash-auth-discord@0.1.0","maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"homepage":"https://github.com/leCielEtoile/emdash-auth-discord#readme","bugs":{"url":"https://github.com/leCielEtoile/emdash-auth-discord/issues"},"dist":{"shasum":"ad8be9473972eab1edf5817cd109d4b504de5acb","tarball":"https://registry.npmjs.org/emdash-auth-discord/-/emdash-auth-discord-0.1.0.tgz","fileCount":12,"integrity":"sha512-10yCLXXHmoPM9R8AxOz/5ApLrZHMPmtAB3V+VOmf0hpLmVo138wlWpbPdSztiOMgF4XESCJ+ux7E8JvmUFnGMg==","signatures":[{"sig":"MEYCIQCP/0HlA4ccKGf1dX6qwusPtQuasdfb6Kg52JTCYvInHwIhAKOkcNYOZJsxrfKJ7sob5Bk2eyBylciEhdMzNicTpzp4","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQD2YX8GaiZOir3ert5OjVdtyJxbYMEGvqeUSRFp2K0MggIgYnbNWoHAjz841NNe5ZaI9uZnE6QjHRA7YYz0V3cSwP4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":65446},"type":"module","engines":{"node":">=22"},"exports":{".":"./index.js","./package.json":"./package.json","./testing/mock-discord":"./test/mock-discord.mjs"},"gitHead":"576b9df0b2bf5b5e945f8fd9f03deba2280f76aa","scripts":{"test":"vitest run","check":"node scripts/check-package.mjs"},"_npmUser":{"name":"lecieletoile","email":"develop@leciel.dev"},"repository":{"url":"git+https://github.com/leCielEtoile/emdash-auth-discord.git","type":"git"},"_npmVersion":"11.19.0","description":"Discord login for EmDash, restricted to members of a Discord guild (role assignment and login records)","directories":{},"_nodeVersion":"24.21.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"packageManager":"pnpm@12.4.2","devDependencies":{"vite":"^8.0.0","react":"^19.3.0","vitest":"^5.0.3","react-dom":"^19.3.0","@emdash-cms/auth":"^1.2.0"},"peerDependencies":{"react":">=18","emdash":">=1.1.0 <2","@emdash-cms/auth":">=1.1.0 <2"},"_npmOperationalInternal":{"tmp":"tmp/emdash-auth-discord_0.1.0_1791791176729_0.7238358087983154","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"emdash-auth-discord","version":"0.1.2","keywords":["emdash","emdash-plugin","discord","oauth","oauth2","auth","authentication","login"],"author":{"name":"leCielEtoile"},"license":"MIT","_id":"emdash-auth-discord@0.1.2","maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"homepage":"https://github.com/leCielEtoile/emdash-auth-discord#readme","bugs":{"url":"https://github.com/leCielEtoile/emdash-auth-discord/issues"},"dist":{"shasum":"254a1d7d09e8aba33361e539bde35371ac45e89a","tarball":"https://registry.npmjs.org/emdash-auth-discord/-/emdash-auth-discord-0.1.2.tgz","fileCount":12,"integrity":"sha512-QK2dhpx4uMgwd0lULxEyUa/aRzEzHXlde0GpDA27lSks9h5Gix6x0c4ymyL6KZzTv2rMa6Odl7f94zvGGRWIVg==","signatures":[{"sig":"MEUCIGFhlMjGnQp3KzdTPyJ2L13V/rcYvxc5Tm62ICvST7rqAiEA2VSBedrvTwrMb4p7ZQVzTZWUGxBBhEs9On+hdO7UpMY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDopNIqE3oi6eh0UyNIBkc29a7JK8aHslfNqOySeU/JDAIgay2bTATxKYxQ/pTBIpDpvU6OhFmS52QftkPvp+PkeWw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-auth-discord@0.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":65143},"type":"module","_from":"file:emdash-auth-discord-0.1.2.tgz","engines":{"node":">=22"},"exports":{".":"./index.js","./package.json":"./package.json","./testing/mock-discord":"./test/mock-discord.mjs"},"scripts":{"test":"vitest run","check":"node scripts/check-package.mjs"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"da23afef-208f-4d53-ac18-9f66b639195d"}},"_resolved":"/home/runner/work/emdash-auth-discord/emdash-auth-discord/emdash-auth-discord-0.1.2.tgz","_integrity":"sha512-QK2dhpx4uMgwd0lULxEyUa/aRzEzHXlde0GpDA27lSks9h5Gix6x0c4ymyL6KZzTv2rMa6Odl7f94zvGGRWIVg==","repository":{"url":"git+https://github.com/leCielEtoile/emdash-auth-discord.git","type":"git"},"_npmVersion":"11.21.0","description":"Discord login for EmDash, restricted to members of a Discord guild (role assignment and login records)","directories":{},"_nodeVersion":"24.21.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.0","react":"^19.3.0","vitest":"^5.0.3","react-dom":"^19.3.0","@emdash-cms/auth":"^1.2.0"},"peerDependencies":{"react":">=18","emdash":">=1.1.0 <2","@emdash-cms/auth":">=1.1.0 <2"},"_npmOperationalInternal":{"tmp":"tmp/emdash-auth-discord_0.1.2_1791794752910_0.9120250608000304","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"emdash-auth-discord","version":"0.1.3","keywords":["emdash","emdash-plugin","discord","oauth","oauth2","auth","authentication","login"],"author":{"name":"leCielEtoile"},"license":"MIT","_id":"emdash-auth-discord@0.1.3","maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"homepage":"https://github.com/leCielEtoile/emdash-auth-discord#readme","bugs":{"url":"https://github.com/leCielEtoile/emdash-auth-discord/issues"},"dist":{"shasum":"18dbd6a8a9bffb79c3cef0666758fe4383d2293b","tarball":"https://registry.npmjs.org/emdash-auth-discord/-/emdash-auth-discord-0.1.3.tgz","fileCount":12,"integrity":"sha512-YMx2IXAwHE0012QD41iIFhl5Qprd74FU9PEQsWrj5qyiND39bNKYaSKWfKk2CTPaHlTlZdRGqAlYqz/HM+m/YQ==","signatures":[{"sig":"MEUCIHegvlPbNOOeStenwdaIbO37AMSfgc2INzt2yUxHr562AiEAtS3TzVuD9e09gLWJflwmE5PyrQf3JUR25ruF7kkdRzY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIAKXYc9P6t6XfNTGIxMkEY5f7KNnXxEhrzcR724YOoOsAiArtwx0PQ9PBKN4TwJf5/avNRoUThGHVdNjVcTEH/Ufag==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-auth-discord@0.1.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":65982},"type":"module","_from":"file:emdash-auth-discord-0.1.3.tgz","engines":{"node":">=22"},"exports":{".":"./index.js","./package.json":"./package.json","./testing/mock-discord":"./test/mock-discord.mjs"},"scripts":{"test":"vitest run","check":"node scripts/check-package.mjs"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"da23afef-208f-4d53-ac18-9f66b639195d"}},"_resolved":"/home/runner/work/emdash-auth-discord/emdash-auth-discord/emdash-auth-discord-0.1.3.tgz","_integrity":"sha512-YMx2IXAwHE0012QD41iIFhl5Qprd74FU9PEQsWrj5qyiND39bNKYaSKWfKk2CTPaHlTlZdRGqAlYqz/HM+m/YQ==","repository":{"url":"git+https://github.com/leCielEtoile/emdash-auth-discord.git","type":"git"},"_npmVersion":"11.21.1","description":"Discord login for EmDash, restricted to members of a Discord guild (role assignment and login records)","directories":{},"_nodeVersion":"24.21.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.0","react":"^19.3.0","vitest":"^5.0.3","react-dom":"^19.3.0","@emdash-cms/auth":"^1.2.0"},"peerDependencies":{"react":">=18","emdash":">=1.1.0 <2","@emdash-cms/auth":">=1.1.0 <2"},"_npmOperationalInternal":{"tmp":"tmp/emdash-auth-discord_0.1.3_1792751559223_0.5496203242734645","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"emdash-auth-discord","version":"0.1.4","keywords":["emdash","emdash-plugin","discord","oauth","oauth2","auth","authentication","login"],"author":{"name":"leCielEtoile"},"license":"MIT","_id":"emdash-auth-discord@0.1.4","maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"homepage":"https://github.com/leCielEtoile/emdash-auth-discord#readme","bugs":{"url":"https://github.com/leCielEtoile/emdash-auth-discord/issues"},"dist":{"shasum":"5f479e71f5b1e62d7d1db535a19222cae054570f","tarball":"https://registry.npmjs.org/emdash-auth-discord/-/emdash-auth-discord-0.1.4.tgz","fileCount":12,"integrity":"sha512-mk/pM3Lc8R97SM/EoZ5UzkygdD2BbxRuuIaISv1N1Bx8SIbmArbt+FN/VKPS7JFJ8rDUtCGykZKlHefGt7pcYg==","signatures":[{"sig":"MEYCIQDgbrUzTURB+T+dzi5WBsKqFnTzp1ulVRKfCEfi5DziRgIhAMK8S1y0quRXX5VC1Q1YzscCHRF4VW8N7SwabX1/79uX","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIC/7H4MNzttaTzkTK1oQL7MJj1SbngXgJY7bbKEP4HLkAiBjbfR21+frkn3PWZLbajPy87romS8F5tw/i44rqfP8VQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-auth-discord@0.1.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":66432},"type":"module","_from":"file:emdash-auth-discord-0.1.4.tgz","engines":{"node":">=22"},"exports":{".":"./index.js","./package.json":"./package.json","./testing/mock-discord":"./test/mock-discord.mjs"},"scripts":{"test":"vitest run","check":"node scripts/check-package.mjs"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"da23afef-208f-4d53-ac18-9f66b639195d"}},"_resolved":"/home/runner/work/emdash-auth-discord/emdash-auth-discord/emdash-auth-discord-0.1.4.tgz","_integrity":"sha512-mk/pM3Lc8R97SM/EoZ5UzkygdD2BbxRuuIaISv1N1Bx8SIbmArbt+FN/VKPS7JFJ8rDUtCGykZKlHefGt7pcYg==","repository":{"url":"git+https://github.com/leCielEtoile/emdash-auth-discord.git","type":"git"},"_npmVersion":"11.21.1","description":"Discord login for EmDash, restricted to members of a Discord guild (role assignment and login records)","directories":{},"_nodeVersion":"24.21.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.0","react":"^19.3.0","vitest":"^5.0.3","react-dom":"^19.3.1","@emdash-cms/auth":"^1.2.0"},"peerDependencies":{"react":">=18","emdash":">=1.1.0 <2","@emdash-cms/auth":">=1.1.0 <2"},"_npmOperationalInternal":{"tmp":"tmp/emdash-auth-discord_0.1.4_1793350066037_0.6287030320253063","host":"s3://npm-registry-packages-npm-production"}},"0.1.5":{"_id":"emdash-auth-discord@0.1.5","bugs":{"url":"https://github.com/leCielEtoile/emdash-auth-discord/issues"},"dist":{"shasum":"57ef1104cfad9e3c5db42c7cbe3da54031f20a0e","tarball":"https://registry.npmjs.org/emdash-auth-discord/-/emdash-auth-discord-0.1.5.tgz","fileCount":12,"integrity":"sha512-TfkAkiX2PK8akKk0mv6BWDg+WrfTPInKKISaF8LfulmTGnDvLNI9ndUoBBVVO7vtvOzk6kEMEkkzjES2WDoYow==","signatures":[{"sig":"MEQCIA1tz5dgtIYDCTshGWnHZie8LTuotkV9sY2SUyyHuJQKAiAKzgDhEAiUlUgiTe6Iv1lX3x9AcqFTi9MAuFNAptdb7A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFv4V9/yXWV67j63QK0tNiaUyR35d/QsEhL5PNcEF3UcAiBByJw17c4MwpYlfHDbV82EYGTkPVyGAxLrqLKdFCA3+Q=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-auth-discord@0.1.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":66793},"name":"emdash-auth-discord","type":"module","_from":"file:emdash-auth-discord-0.1.5.tgz","author":{"name":"leCielEtoile"},"engines":{"node":">=22"},"exports":{".":"./index.js","./package.json":"./package.json","./testing/mock-discord":"./test/mock-discord.mjs"},"license":"MIT","scripts":{"test":"vitest run","check":"node scripts/check-package.mjs"},"version":"0.1.5","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"da23afef-208f-4d53-ac18-9f66b639195d"}},"homepage":"https://github.com/leCielEtoile/emdash-auth-discord#readme","keywords":["emdash","emdash-plugin","discord","oauth","oauth2","auth","authentication","login"],"_resolved":"/home/runner/work/emdash-auth-discord/emdash-auth-discord/emdash-auth-discord-0.1.5.tgz","_integrity":"sha512-TfkAkiX2PK8akKk0mv6BWDg+WrfTPInKKISaF8LfulmTGnDvLNI9ndUoBBVVO7vtvOzk6kEMEkkzjES2WDoYow==","repository":{"url":"git+https://github.com/leCielEtoile/emdash-auth-discord.git","type":"git"},"_npmVersion":"11.21.3","description":"Discord login for EmDash, restricted to members of a Discord guild (role assignment and login records)","directories":{},"maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"_nodeVersion":"24.21.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.0","react":"^19.3.0","vitest":"^5.0.3","react-dom":"^19.3.1","@emdash-cms/auth":"^1.2.0"},"peerDependencies":{"react":">=18","emdash":">=1.1.0 <2","@emdash-cms/auth":">=1.1.0 <2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/emdash-auth-discord_0.1.5_1795471275383_0.5922267080114918"}}},"time":{"created":"2026-10-12T07:44:09.171Z","modified":"2026-11-23T22:01:15.874Z","0.0.0-stage":"2026-10-12T07:44:09.171Z","0.1.0":"2026-10-12T07:46:16.820Z","0.1.2":"2026-10-12T08:45:53.006Z","0.1.3":"2026-10-23T10:32:39.307Z","0.1.4":"2026-10-30T08:47:46.123Z","0.1.5":"2026-11-23T22:01:15.491Z"},"bugs":{"url":"https://github.com/leCielEtoile/emdash-auth-discord/issues"},"author":{"name":"leCielEtoile"},"license":"MIT","homepage":"https://github.com/leCielEtoile/emdash-auth-discord#readme","keywords":["emdash","emdash-plugin","discord","oauth","oauth2","auth","authentication","login"],"repository":{"url":"git+https://github.com/leCielEtoile/emdash-auth-discord.git","type":"git"},"description":"Discord login for EmDash, restricted to members of a Discord guild (role assignment and login records)","maintainers":[{"name":"lecieletoile","email":"develop@leciel.dev"}],"readme":"# emdash-auth-discord\n\nEnglish | [日本語](./README.ja.md)\n\nDiscord login (an authentication provider) for EmDash. Only members of a Discord guild (server) you specify can sign in.\n\n## Features\n\n- Signs in with Discord OAuth2 (authorization code flow with PKCE/S256) and adds a \"Log in with Discord\" button to the EmDash login screen (the label is configurable with `loginLabel`).\n- Fetches the user's guild list with the `guilds` scope (200 guilds per page, up to 10 pages) and rejects anyone who is not a member of `guildId`.\n- Rejects users whose Discord email is not verified (`email_not_verified`).\n- On every login, syncs the display name and avatar, and records login details in `users.data.discord` (login count, etc.).\n- Roles: users listed in `adminIds` become Admin; everyone else gets `defaultRole` (default `10`, Subscriber). No one becomes Admin automatically unless you opt in to `bootstrapFirstAdmin`.\n- When an Admin logs in through Discord, completes EmDash's initial setup (`emdash:setup_complete`) if it is not complete yet.\n\n> **Warning: guild membership is the only gate.** Every member of `guildId` can log in and is registered with `defaultRole`. If anyone can join your guild (for example through a public invite link), anyone can get that role. Keep `defaultRole` at the minimum you need, and grant higher roles in EmDash afterwards.\n\n## Requirements\n\n- Node.js >= 22\n- Peer dependencies (provided by your app): `emdash >=1.1.0 <2`, `@emdash-cms/auth >=1.1.0 <2`, `react >=18`. Verified with `emdash` 1.2.0.\n- A Discord application with OAuth2 enabled\n\n## Installation\n\nInstall it from npm:\n\n```bash\npnpm add emdash-auth-discord\n```\n\nReleases are published by this repository's release workflow with [npm provenance](https://docs.npmjs.com/generating-provenance-statements), so the npm page links back to `github.com/leCielEtoile/emdash-auth-discord`. To pin a specific version, use `pnpm add emdash-auth-discord@<version>` (for example `0.1.2`).\n\nEach GitHub Release attaches the tarball and SBOMs (`sbom.cdx.json` in CycloneDX, `sbom.spdx.json` in SPDX) generated by `pnpm sbom`. Only the CycloneDX SBOM is signed as an attestation; verify it with `gh attestation verify <tarball> -R leCielEtoile/emdash-auth-discord --predicate-type https://cyclonedx.org/bom`.\n\n## Setup\n\n1. In the [Discord Developer Portal](https://discord.com/developers/applications), create an application. No bot is needed.\n2. Under **OAuth2**, copy the **Client ID** and **Client Secret**, and add this redirect URI:\n\n   ```\n   <your public URL>/_emdash/api/auth/discord/callback\n   ```\n\n   `<your public URL>` must match `EMDASH_SITE_URL` exactly (scheme, host, and port).\n3. Get your guild ID: in Discord, enable **Settings > Advanced > Developer Mode**, right-click the server, and choose **Copy Server ID**. Copy your own user ID the same way (right-click your name > **Copy User ID**) for `adminIds`.\n4. Set the environment variables (for example in `.env`, which must not be committed):\n\n   ```bash\n   DISCORD_CLIENT_ID=123456789012345678\n   DISCORD_CLIENT_SECRET=your-client-secret\n   DISCORD_GUILD_ID=100000000000000001      # read by the example config below\n   DISCORD_ADMIN_IDS=200000000000000001     # your Discord user ID\n   EMDASH_SITE_URL=https://cms.example.com\n   ```\n\n5. Add the provider to `astro.config.mjs`:\n\n   ```js\n   import { defineConfig } from \"astro/config\"\n   import emdash from \"emdash/astro\"\n   import { discord } from \"emdash-auth-discord\"\n\n   export default defineConfig({\n   \tintegrations: [\n   \t\temdash({\n   \t\t\tauthProviders: [\n   \t\t\t\tdiscord({\n   \t\t\t\t\tguildId: process.env.DISCORD_GUILD_ID,\n   \t\t\t\t\tdefaultRole: 10,\n   \t\t\t\t\tsiteTitle: \"My Site\",\n   \t\t\t\t\tmessages: { notGuildMember: \"Only members of the My Site Discord server can log in.\" },\n   \t\t\t\t}),\n   \t\t\t],\n   \t\t}),\n   \t],\n   })\n   ```\n\n## Options (`discord({...})`)\n\nOptions are validated when `discord()` is called. Invalid values throw an error at startup instead of failing silently at login.\n\n| Option | Type | Default | Description |\n| --- | --- | --- | --- |\n| `guildId` | `string` (17-20 digits) | none (required) | ID of the guild whose members may log in. Pass it as a string; numbers lose precision. If unset, every login is rejected (fail-closed). |\n| `defaultRole` | `10 \\| 20 \\| 30 \\| 40` | `10` (Subscriber) | Role given to new non-admin users. `50` (Admin) is not allowed here; use `adminIds`. |\n| `adminIds` | `string[]` (17-20 digits each) | `[]` | Discord user IDs that become Admin. Merged (union) with `DISCORD_ADMIN_IDS`. |\n| `bootstrapFirstAdmin` | `boolean` | `false` | When `true` (or `DISCORD_BOOTSTRAP_FIRST_ADMIN=1`), the first guild member to log in becomes Admin, but only while EmDash's initial setup is not complete. See [Behavior](#behavior). |\n| `scopes` | `string[]` | `[\"identify\", \"email\", \"guilds\"]` | OAuth scopes to request. Must include the three defaults. |\n| `siteTitle` | `string` | `\"EmDash\"` | Site title stored on initial setup completion, only if no site title is set yet. |\n| `loginLabel` | `string` | `\"Log in with Discord\"` | Text of the login button. |\n| `messages` | `Record<string, string>` | English defaults | Messages shown on the login screen, keyed by error code in camelCase (see below). |\n\nRole values: `10` Subscriber, `20` Contributor, `30` Author, `40` Editor, `50` Admin.\n\n`messages` keys: `providerNotConfigured`, `serverError`, `invalidCallback`, `invalidState`, `oauthDenied`, `notGuildMember`, `emailRequired`, `emailNotVerified`, `signupNotAllowed`, `accountDisabled`, `userNotFound`, `rateLimited`, `discordTimeout`, `tokenExchangeFailed`, `profileFetchFailed`, `guildFetchFailed`, `oauthError`. Unknown keys are rejected. See [README.ja.md](./README.ja.md) for a Japanese example.\n\n## Environment variables\n\n| Variable | Required | Description |\n| --- | --- | --- |\n| `DISCORD_CLIENT_ID` | Yes | OAuth2 client ID. |\n| `DISCORD_CLIENT_SECRET` | Yes (secret) | OAuth2 client secret. Never commit it or write it to logs. |\n| `DISCORD_ADMIN_IDS` | No | Comma-separated Discord user IDs (17-20 digits) to make Admin. Merged with `adminIds`. An invalid ID makes login fail with `provider_not_configured` instead of being ignored. |\n| `DISCORD_BOOTSTRAP_FIRST_ADMIN` | No | `1` enables `bootstrapFirstAdmin`. Any other value leaves it off. |\n| `EMDASH_SITE_URL` | Yes in production | Public URL, used to build the redirect URI. EmDash's `siteUrl` setting is used if this is unset. When `NODE_ENV=production` and neither is set, login fails with `provider_not_configured` (the request's Host header is not trusted). In development it falls back to the request origin. |\n| `DISCORD_BASE_URL` | No (tests only) | Discord base URL (default `https://discord.com`). Only `https`, or `http` on `localhost` / `127.0.0.1`, is accepted. When `NODE_ENV=production`, anything other than `https://discord.com` is an error. |\n| `NODE_ENV` | Recommended | Set `production` in production to enable the checks above. |\n\nSettings such as `guildId` and `defaultRole` are passed as options, not environment variables. Read `process.env` in your app config and pass the values in, as in the example above.\n\n## Behavior\n\n- On failure the user is sent back to `/_emdash/admin/login?error=<code>&message=<message>`. The message is a fixed text per code (English by default, overridable with `messages`); Discord's `error_description` and internal error messages are never shown. Codes: `provider_not_configured`, `server_error`, `invalid_callback`, `invalid_state`, `oauth_denied`, `not_guild_member`, `email_required`, `email_not_verified`, `signup_not_allowed`, `account_disabled`, `user_not_found`, `rate_limited`, `discord_timeout`, `token_exchange_failed`, `profile_fetch_failed`, `guild_fetch_failed`, `oauth_error`.\n- Every failure is logged on the server as `[discord-auth] login failed: <code> {...}` with non-secret details (HTTP status, `Retry-After`, missing setting names). Client secrets, access tokens, and authorization codes are never logged.\n- Each Discord API call times out after 10 seconds (`discord_timeout`). HTTP 429 becomes `rate_limited` and the `Retry-After` value is logged. Requests are not retried.\n- `state` is read and deleted from the session before it is checked, so a used or rejected `state` cannot be used again, and it expires after 10 minutes. PKCE (S256) is used for the token exchange. The session ID is regenerated on successful login (session fixation protection).\n- Role decision: a Discord ID in the admin IDs (`adminIds` ∪ `DISCORD_ADMIN_IDS`) gets Admin (50). Otherwise, if `bootstrapFirstAdmin` is enabled **and** `emdash:setup_complete` is not set, the first person to log in becomes Admin; a warning is logged when this happens. Everyone else gets `defaultRole`.\n- An existing user whose ID is later added to the admin IDs is promoted to Admin on their next login. Users are never demoted automatically.\n- Login record: `users.data.discord` stores the Discord ID, username, locale, first/last login time, and login count.\n\n## Security notes and limitations\n\n- Keep `DISCORD_CLIENT_SECRET` out of version control and logs.\n- Prefer `adminIds`. Enable `bootstrapFirstAdmin` only for the first deployment, log in yourself before anyone else can, then set `adminIds` and turn it off. The \"first admin\" slot is claimed atomically in the `options` table (`INSERT ... ON CONFLICT DO NOTHING`), so two simultaneous logins cannot both become Admin through it, and it is never granted after setup is complete.\n- **Leaving or being banned from the guild does not end existing sessions.** Membership is checked only at login. To revoke access immediately, disable the user in EmDash (disabled users are rejected at login).\n- **Accounts are linked by verified email.** If a Discord account has the same verified email as an existing EmDash user (including an Admin created with a passkey), logging in with Discord signs in as that user. This lowers that account's protection to the Discord account's. Do not use the same email for a passkey Admin and a Discord account you do not fully trust, or disable the matching EmDash user. Disabled users are rejected before any link is created.\n- **The display name and avatar are overwritten from Discord on every login.** Discord display names are user-controlled, so do not rely on display names in EmDash to identify people.\n- The `state` check is one-time per session, but Astro saves session changes when the response finishes, so two requests sent in parallel with the same session cookie and `state` can both pass the check. Discord authorization codes are single-use and PKCE is required, which limits the impact.\n- Verified on the Node adapter. Environment variables are read from `process.env` first, then fall back to `virtual:emdash/env`. Behavior on Cloudflare Workers is untested.\n- This is a native plugin that depends on EmDash internal APIs (`OptionsRepository`, `AuthProviderDescriptor`, the `virtual:emdash/auth-providers` module). They may change between EmDash versions, so the peer range is capped below 2.0.\n- Guild membership is checked against at most 2000 guilds (200 per page x 10 pages). Users in more guilds are rejected with `guild_fetch_failed`.\n- Report vulnerabilities privately as described in [SECURITY.md](./SECURITY.md) (GitHub private vulnerability reporting).\n\n## Testing\n\n```bash\npnpm install\npnpm test     # unit tests, route tests (login / callback) and package check tests\npnpm check    # package sanity checks on the files that are actually published\n```\n\n- Maintainers: project-specific names are checked by `pnpm check` through an optional, git-ignored `.check-package.private-terms` file (one term per line; or set `CHECK_PACKAGE_PRIVATE_TERMS_FILE`). The check is skipped when the file is absent.\n\nRoute tests drive `routes/login.js` and `routes/callback.js` with the real `@emdash-cms/auth` and an in-memory database and session.\n\nA mock Discord server is exported as `emdash-auth-discord/testing/mock-discord` (`test/mock-discord.mjs`) **for tests only**. It issues tokens for any user with a fixed secret, so never run it in production: it binds to `127.0.0.1` only and refuses to start when `NODE_ENV=production`. Start it with `node node_modules/emdash-auth-discord/test/mock-discord.mjs` (port from the `PORT` environment variable, default 4400), then run your app with `DISCORD_BASE_URL=http://127.0.0.1:4400` and `DISCORD_CLIENT_SECRET=mock-secret`. Add `as=<a|b|c|d|e>` to the authorize URL to choose the mock user, or `deny=1` to simulate a denied login.\n\n`pnpm-workspace.yaml` configures stand-alone development of this package (peer dependencies are not installed automatically).\n\n## License\n\n[MIT](./LICENSE)\n","readmeFilename":"README.md"}