next-auth-steam
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

next-auth-steam

steam authentication provider for next-auth.

Usage

Using App Router

// app/api/auth/[...nextauth]/route.ts
import NextAuth from 'next-auth'
import SteamProvider from 'next-auth-steam'

import type { NextRequest } from 'next/server'

async function handler(
  req: NextRequest,
  ctx: { params: { nextauth: string[] } }
) {
  return NextAuth(req, ctx, {
    providers: [
      SteamProvider(req, {
        clientSecret: process.env.STEAM_SECRET!,
        callbackUrl: 'http://localhost:3000/api/auth/callback'
      })
    ]
  })
}

export {
  handler as GET,
  handler as POST
}

Using Pages Router

// pages/api/auth/[...nextauth].ts
import NextAuth from 'next-auth'
import SteamProvider from 'next-auth-steam'

import type { NextApiRequest, NextApiResponse } from 'next'

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  return NextAuth(req, res, {
    providers: [
      SteamProvider(req, {
        clientSecret: process.env.STEAM_SECRET!,
        callbackUrl: 'http://localhost:3000/api/auth/callback'
      })
    ]
  })
}

Retrieving Steam profile data

Use next-auth's callbacks to retrieve Steam profile data:

import { PROVIDER_ID } from 'next-auth-steam'

// Inside `handler` function
return NextAuth(req, res, {
  providers: [
    SteamProvider(req, {
      clientSecret: process.env.STEAM_SECRET!,
      callbackUrl: 'http://localhost:3000/api/auth/callback'
    })
  ],
  callbacks: {
    jwt({ token, account, profile }) {
      if (account?.provider === PROVIDER_ID) {
        token.steam = profile
      }

      return token
    },
    session({ session, token }) {
      if ('steam' in token) {
        // @ts-expect-error
        session.user.steam = token.steam
      }

      return session
    }
  }
})

// Somewhere in your components
import { useSession, signIn, signOut } from "next-auth/react"

export default function Component() {
  const { data } = useSession()

  return <div>Hello, {data?.user.steam.personaname}</div>
}

More examples are in examples folder.

Readme

Keywords

none

Package Sidebar

Install

npm i next-auth-steam

Weekly Downloads

125

Version

0.3.0

License

WTFPL

Unpacked Size

12.6 kB

Total Files

10

Last publish

Collaborators

  • nekonyx