Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import { type NodeSavedState, type NodeSavedSession, type NodeSavedStateStore, type NodeSavedSessionStore, NodeOAuthClient} from "@atproto/oauth-client-node";
// Maps are setup for local development// For production, update the variables and classes to use a persistent databaseconst stateStore = new Map<string, NodeSavedState>();const sessionStore = new Map<string, NodeSavedSession>();
class AuthStateStore implements NodeSavedStateStore { constructor() {}
async get(key: string) { return stateStore.get(key); }
async set(key: string, val: NodeSavedState) { stateStore.set(key, val); }
async del(key: string) { stateStore.delete(key); }}
class AuthSessionStore implements NodeSavedSessionStore { constructor() {}
async get(key: string) { return sessionStore.get(key); }
async set(key: string, val: NodeSavedSession) { sessionStore.set(key, val); }
async del(key: string) { sessionStore.delete(key); }}
const enc = encodeURIComponent;const devMode = process.env.NODE_ENV === "development";const BASE_URL = devMode ? "http://127.0.0.1:3000" : "https://atp-tanstack-demo.zeu.dev";const CALLBACK_URL = `${BASE_URL}/oauth/callback`;const SCOPE = "atproto transition:generic";
export const oauth = new NodeOAuthClient({ clientMetadata: { client_name: "ATP TanStack Demo", client_uri: BASE_URL, client_id: devMode ? `http://localhost?redirect_uri=${enc(CALLBACK_URL)}&scope=${enc(SCOPE)}` : `${BASE_URL}/oauth-client-metadata.json`, scope: SCOPE, redirect_uris: [CALLBACK_URL], application_type: "web", grant_types: ["authorization_code", "refresh_token"], token_endpoint_auth_method: "none", dpop_bound_access_tokens: true }, stateStore: new AuthStateStore(), sessionStore: new AuthSessionStore()});