forked from
samuel.fm/statusphere-react
the statusphere demo reworked into a vite/react app in a monorepo
1import { NodeOAuthClient } from '@atproto/oauth-client-node'
2
3import type { Database } from '#/db'
4import { env } from '#/lib/env'
5import { SessionStore, StateStore } from './storage'
6
7export const createClient = async (db: Database) => {
8 if (env.isProduction && !env.PUBLIC_URL) {
9 throw new Error('PUBLIC_URL is not set')
10 }
11
12 const publicUrl = env.PUBLIC_URL
13 const url = publicUrl || `http://127.0.0.1:${env.VITE_PORT}`
14 const enc = encodeURIComponent
15
16 return new NodeOAuthClient({
17 clientMetadata: {
18 client_name: 'Statusphere React App',
19 client_id: publicUrl
20 ? `${url}/oauth-client-metadata.json`
21 : `http://localhost?redirect_uri=${enc(`${url}/oauth/callback`)}&scope=${enc('atproto transition:generic')}`,
22 client_uri: url,
23 redirect_uris: [`${url}/oauth/callback`],
24 scope: 'atproto transition:generic',
25 grant_types: ['authorization_code', 'refresh_token'],
26 response_types: ['code'],
27 application_type: 'web',
28 token_endpoint_auth_method: 'none',
29 dpop_bound_access_tokens: true,
30 },
31 stateStore: new StateStore(db),
32 sessionStore: new SessionStore(db),
33 })
34}