5.3 KiB
5.3 KiB
name, description, argument-hint
| name | description | argument-hint |
|---|---|---|
| discord-oauth-vue3-vite | Use when scaffolding Discord OAuth into a Vue 3 + Vite app with a server bundle under src/server, PKCE, session handling, and route protection. | project-root=<path> mode=<dry-run|apply> frontend-origin=<url> allowlist-discord-ids=<csv> |
Discord OAuth Vue 3 + Vite
Use this skill when you want a portable, repeatable Discord OAuth setup for a Vue 3 + Vite app and you want the server-side auth bundle kept under src/server/ instead of a standalone scripts/ service.
Procedure
Server bundle
- Confirm the target project root and review the generated server bundle path, which defaults to
src/server/discord-oauth. - Confirm the user-owned prerequisites: a Discord application, the authorized redirect URI, client ID, client secret, and any Discord user IDs that should be allowlisted.
- Run
resources/scripts/scaffold-discord-oauth-vue3-vite.shin--mode dry-runfirst when the shared resources repo is available; if the script path is not available in the current workspace, continue with the manual scaffold path instead of stopping. - Let the scaffold create the auth bundle under
src/server/with PKCE state handling, Discord token exchange, profile fetch, allowlist checks, refresh-session rotation, and logout cleanup. - Copy the generated
clients.example.jsontoclients.jsonand fill in the Discord client credentials and frontend origin values. - Set
AUTH_PORT,JWT_SECRET, and the other auth env vars locally. Align the Discord redirect URI with the app callback route (<frontendOrigin>/oauth/callback?provider=discord).
Client-side wiring
- Create
useAuth.jsas a module-level singleton composable undersrc/client/src/composables/using the reference template atresources/templates/discord-oauth-vue3-vite/src/client/composables/useAuth.js. The singleton exposesuser,features,isLoading,isLoggedIn,checkSession(),login(),logout(), andsetSession(). - Create
DiscordAuthWidgetas an organism undersrc/client/src/components/organisms/with a colocated SCSS file and a stories stub, using the reference templates atresources/templates/discord-oauth-vue3-vite/src/client/components/organisms/. Update the SCSS@usepaths to match the target project's style foundation before placing. Both the.vueand.scssmust exist; the stories stub must exportLoggedOutandLoggedIn. - Create
OAuthCallbackPage.vueundersrc/client/src/pages/using the reference template atresources/templates/discord-oauth-vue3-vite/src/client/pages/OAuthCallbackPage.vue. Register it on the/oauth/callbackroute with nometa.requiresAuthguard. - Add a
beforeEachrouter guard: callcheckSession()before any route withmeta.requiresAuth: trueand redirect to/ifisLoggedInis false. Mark protected routes withmeta: { requiresAuth: true }. - Add a Vite dev proxy entry for
/api/authpointing tohttp://localhost:<AUTH_PORT>invite.config.js.
Runtime and validation
- Either run the auth server as its own Node process (add an
auth:devscript:node src/server/discord-oauth/server.js) or mount it into an existing backend entrypoint. - Validate the flow: start login, complete the callback, check the session endpoint, refresh the session, and log out. Confirm the allowlist rejects an unapproved Discord account.
Outputs
Server bundle (scaffold script writes these):
src/server/discord-oauth/server.jssrc/server/discord-oauth/config.jssrc/server/discord-oauth/sessionStore.jssrc/server/discord-oauth/allowlist.jssrc/server/discord-oauth/providers/discord.jssrc/server/discord-oauth/lib/oauth/pkce.jssrc/server/discord-oauth/lib/oauth/providers.jssrc/server/discord-oauth/clients.example.jsonsrc/server/discord-oauth/README.md
Client files (placed from reference templates; adapt paths per project):
src/client/src/composables/useAuth.jssrc/client/src/components/organisms/DiscordAuthWidget.vuesrc/client/src/components/organisms/DiscordAuthWidget.scsssrc/client/src/components/organisms/DiscordAuthWidget.stories.jssrc/client/src/pages/OAuthCallbackPage.vue
Do Not Use
- Do not use this workflow when the project does not have a Node-side runtime path for auth code under
src/server/. - Do not use this workflow when the project uses a hosted auth provider or a managed backend where Discord auth should not live in the repo.
- Do not store secrets in the generated files.
Notes
- This workflow follows the proven pattern: origin-specific client config, PKCE, Discord code exchange, allowlist gating, refresh-token rotation, and cookie cleanup.
- Client template files live in
resources/templates/discord-oauth-vue3-vite/src/client/and are reference-only. Adapt component paths and SCSS@useimports to match the target project's conventions before placing them. - Projects using atomic design require colocated SCSS and a stories stub for every organism; the
DiscordAuthWidgettemplates satisfy this by default. - Keep the generated bundle generic to Vue 3 + Vite so the same path can be reused in other apps.
- If the project does not already have a server entrypoint, add an
auth:devscript that runsnode src/server/discord-oauth/server.js, then configure Vite to proxy/api/authto that port.