A simple Discord login demo built with Next.js. It is meant for debugging and learning how OAuth redirects work, not for production authentication.
The app lets a user sign in with Discord, fetches their Discord profile, stores the demo session in localStorage, keeps the user signed in after refresh, and clears everything on logout.
- Discord login with the OAuth implicit flow
- No database and no backend session storage
- Local refresh persistence with
localStorage - Clean logout that clears the local demo session
- Visible login/logout flow log for debugging
- Clear missing-config warning when the Discord client ID is not set
- Modern responsive UI with a profile/details panel
This project intentionally stores the Discord access token in the browser so the flow is easy to inspect. That is fine for a local learning tool, but do not use this pattern for production authentication.
- Node.js
- pnpm
- A Discord application client ID
- Go to the Discord Developer Portal.
- Create a new application.
- Copy the application client ID.
- Open
OAuth2. - Add this redirect URL:
http://localhost:3000/auth/callback
The redirect URL must match exactly. If you run the app on a different port or hostname, add that exact callback URL in Discord too.
Install dependencies:
pnpm installCreate your local environment file:
cp .env.local.example .env.localSet your Discord client ID:
NEXT_PUBLIC_DISCORD_CLIENT_ID=your_discord_client_id_hereStart the dev server:
pnpm devOpen:
http://localhost:3000
pnpm devRuns the local Next.js development server.
pnpm buildBuilds the app for production.
pnpm startStarts the production build after pnpm build.
pnpm lintRuns ESLint.
- The home page checks for
NEXT_PUBLIC_DISCORD_CLIENT_ID. - Login creates an OAuth
statevalue and redirects to Discord. - Discord redirects back to
/auth/callbackwith an access token in the URL hash. - The callback page validates
state, fetcheshttps://discord.com/api/v10/users/@me, and stores the session inlocalStorage. - The home page reads the saved session after refresh.
- Logout removes the saved session and OAuth state from
localStorage.
If the login button is disabled, check that .env.local exists and contains NEXT_PUBLIC_DISCORD_CLIENT_ID.
If Discord says the redirect URI is invalid, make sure the Discord Developer Portal contains exactly:
http://localhost:3000/auth/callback
If you change .env.local, restart the dev server so Next.js can load the new value.
app/
auth/callback/page.tsx Discord OAuth callback handler
globals.css App styling
layout.tsx App metadata and root layout
page.tsx Main login demo UI