JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 106
  • Score
    100M100P100Q86922F
  • License MIT

Remix authentication strategy for Steam

Package Exports

  • @ianlucas/remix-auth-steam
  • @ianlucas/remix-auth-steam/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ianlucas/remix-auth-steam) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

remix-auth-steam

A Steam strategy for Remix Auth library

Install

npm install @ianlucas/remix-auth-steam

Usage

Adding it to Remix Auth

import { SteamStrategy as BaseSteamStrategy } from "@ianlucas/remix-auth-steam";
import { Strategy } from "remix-auth/strategy";
import SteamAPI, { type UserSummary } from "steamapi";

class SteamStrategy extends BaseSteamStrategy<string> {
    constructor() {
        super(
            async () => ({
                returnURL: STEAM_CALLBACK_URL
            }),
            async ({ userID }) =>
                await upsertUser((await new SteamAPI(STEAM_API_KEY).getUserSummary(userID)) as UserSummary)
        );
    }
}

export const authenticator = new Authenticator<string>();
authenticator.use(new SteamStrategy(), "steam");

Using it in routes

sign-in._index.tsx

export async function loader({ request }: Route.LoaderArgs) {
    return authenticator.authenticate("steam", request);
}

sign-in.steam.callback._index.tsx

export async function loader({ request }: Route.LoaderArgs) {
    const userId = await authenticator.authenticate("steam", request);
    const session = await getSession(request.headers.get("cookie"));
    session.set("userId", userId);
    throw redirect("/", {
        headers: {
            "Set-Cookie": await commitSession(session)
        }
    });
}