This guide walks you through adding Steam authentication to Auth.js (NextAuth.js v5). Since Auth.js now runs on the edge, we need a browser-compatible approach, avoiding Node.js-specific packages like crypto
.
Note: This tutorial is based on Next.js, but the same approach can be adapted for other frameworks that support Auth.js. The key parts are handling OpenID authentication, passing the required parameters, and ensuring compatibility with an edge runtime.
Heavily inspired by next-auth-steam (Steam authentication provider for NextAuth.js v4).
Below is the recommended structure for integrating Steam authentication:
your-project/
โโโ providers/
โ โโโ steam.ts # Steam authentication provider
โโโ types/
โ โโโ auth.d.ts # TypeScript definitions for Steam user data
โโโ app/
โ โโโ api/
โ โ โโโ auth/
โ โ โ โโโ verify/
โ โ โ โ โโโ route.ts # Dummy token route for Steam authentication
โโโ auth.ts # Auth.js configuration
Before you start, install the required package:
pnpm install openid
Since this is just a tutorial, there is no package.json
providedโyou'll need to add the files manually into your existing Auth.js setup.
.env
file and add:NEXTAUTH_URL=https://mywebsite.com
NEXTAUTH_STEAM_SECRET=<your-steam-api-key>
Create the Steam Provider
steam.ts
inside the providers/
directory. Update Your Auth Configuration
auth.ts
file to use the Steam provider. callbackUrl
matches the verification route in the next step.Create a Dummy Token Route
app/api/auth/verify/route.ts
.Define TypeScript Types
types/auth.d.ts
. /api/auth/verify/
route can be renamed, but it must match callbackUrl
in auth.ts
. pnpm install openid
. .env
file.