diff --git a/.gitignore b/.gitignore index 51e048c..51f7fef 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ count.txt .env .nitro .tanstack -public/client-metadata.json \ No newline at end of file +public/client-metadata.json +public/resolvers.json diff --git a/README.md b/README.md index 18bb713..3e4c999 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,15 @@ the PROD_URL is what will compile your oauth client metadata so it is very impor run dev with `npm run dev` (port 3768) and build with `npm run build` (the output is the `dist` folder) + + +you probably dont need to change these +```ts +const PROD_HANDLE_RESOLVER_PDS = "https://pds-nd.whey.party" +const DEV_HANDLE_RESOLVER_PDS = "https://bsky.social" +``` +if you do want to change these, i recommend changing both of these to your own PDS url. i separate the prod and dev urls so that you can change it as needed. here i separated it because if the prod resolver and prod url shares the same domain itll error and prevent logins + ## useQuery Red Dwarf has been upgraded from its original bespoke caching system to Tanstack Query (react query). this migration was done to achieve a more robust and maintainable approach to data fetching and caching and state synchronization. ive seen serious performance gains from this switch! diff --git a/oauthdev.mts b/oauthdev.mts index 70314ef..2529126 100644 --- a/oauthdev.mts +++ b/oauthdev.mts @@ -1,48 +1,79 @@ -import fs from 'fs'; -import path from 'path'; +import fs from "fs"; +import path from "path"; //import { generateClientMetadata } from './src/helpers/oauthClient' export const generateClientMetadata = (appOrigin: string) => { - const callbackPath = '/callback'; + const callbackPath = "/callback"; return { - "client_id": `${appOrigin}/client-metadata.json`, - "client_name": "ForumTest", - "client_uri": appOrigin, - "logo_uri": `${appOrigin}/logo192.png`, - "tos_uri": `${appOrigin}/terms-of-service`, - "policy_uri": `${appOrigin}/privacy-policy`, - "redirect_uris": [`${appOrigin}${callbackPath}`] as [string, ...string[]], - "scope": "atproto transition:generic", - "grant_types": ["authorization_code", "refresh_token"] as ["authorization_code", "refresh_token"], - "response_types": ["code"] as ["code"], - "token_endpoint_auth_method": "none" as "none", - "application_type": "web" as "web", - "dpop_bound_access_tokens": true - }; -} - + client_id: `${appOrigin}/client-metadata.json`, + client_name: "ForumTest", + client_uri: appOrigin, + logo_uri: `${appOrigin}/logo192.png`, + tos_uri: `${appOrigin}/terms-of-service`, + policy_uri: `${appOrigin}/privacy-policy`, + redirect_uris: [`${appOrigin}${callbackPath}`] as [string, ...string[]], + scope: "atproto transition:generic", + grant_types: ["authorization_code", "refresh_token"] as [ + "authorization_code", + "refresh_token", + ], + response_types: ["code"] as ["code"], + token_endpoint_auth_method: "none" as "none", + application_type: "web" as "web", + dpop_bound_access_tokens: true, + }; +}; -export function generateMetadataPlugin({prod, dev}:{prod: string, dev: string}) { +export function generateMetadataPlugin({ + prod, + dev, + prodResolver = "https://bsky.social", + devResolver = prodResolver, +}: { + prod: string; + dev: string; + prodResolver?: string; + devResolver?: string; +}) { return { - name: 'vite-plugin-generate-metadata', + name: "vite-plugin-generate-metadata", config(_config: any, { mode }: any) { - let appOrigin; - if (mode === 'production') { - appOrigin = prod - if (!appOrigin || !appOrigin.startsWith('https://')) { - throw new Error('VITE_APP_ORIGIN environment variable must be set to a valid HTTPS URL for production build.'); + let appOrigin, resolver; + if (mode === "production") { + appOrigin = prod; + resolver = prodResolver; + if (!appOrigin || !appOrigin.startsWith("https://")) { + throw new Error( + "VITE_APP_ORIGIN environment variable must be set to a valid HTTPS URL for production build." + ); } } else { appOrigin = dev; + resolver = devResolver; } - - + const metadata = generateClientMetadata(appOrigin); - const outputPath = path.resolve(process.cwd(), 'public', 'client-metadata.json'); + const outputPath = path.resolve( + process.cwd(), + "public", + "client-metadata.json" + ); fs.writeFileSync(outputPath, JSON.stringify(metadata, null, 2)); + const resolvers = { + resolver: resolver, + }; + const resolverOutPath = path.resolve( + process.cwd(), + "public", + "resolvers.json" + ); + + fs.writeFileSync(resolverOutPath, JSON.stringify(resolvers, null, 2)); + + // /*mass comment*/ console.log(`✅ Generated client-metadata.json for ${appOrigin}`); }, }; -} \ No newline at end of file +} diff --git a/src/utils/oauthClient.ts b/src/utils/oauthClient.ts index 2f017db..5c32f41 100644 --- a/src/utils/oauthClient.ts +++ b/src/utils/oauthClient.ts @@ -1,7 +1,7 @@ import { BrowserOAuthClient, type ClientMetadata } from '@atproto/oauth-client-browser'; -// i tried making this https://pds-nd.whey.party but cors is annoying as fuck -const handleResolverPDS = 'https://bsky.social'; +import resolvers from '../../public/resolvers.json' with { type: 'json' }; +const handleResolverPDS = resolvers.resolver || 'https://bsky.social'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore this should be fine ? the vite plugin should generate this before errors