diff --git a/astro-authproto/README.md b/astro-authproto/README.md index 3527216..6bea007 100644 --- a/astro-authproto/README.md +++ b/astro-authproto/README.md @@ -2,7 +2,7 @@ -ATproto authentication for your Astro site. Free and Easy™! +ATproto authentication for your [Astro](https://docs.astro.build/en/concepts/why-astro/) site. Free and Easy™! @@ -31,8 +31,8 @@ In this package, you'll find: - `@fujocoded/authproto/components`, which includes: - A basic login/logout component to get started quickly - `@fujocoded/authproto/helpers`, - - `getPdsAgent` etc.? - - `friendsOnly` function (or similar) + - `getPdsAgent` authorizes a logged in user to post, update, or delete data from ATProto + - `friendsOnly` finds mutuals from your [Bluesky](https://bsky.app/) account ## What can you do with `@fujocoded/authproto`? @@ -55,6 +55,7 @@ In this package, you'll find: - Make your _own_ ATproto app that shares data with the rest of the network + ## Built with Authproto @@ -68,53 +69,50 @@ In this package, you'll find: - Node - NPM/pnpm/yarn - Terminal +- [Server adapter](https://docs.astro.build/en/guides/on-demand-rendering/#server-adapters) to set up sessions +- (Optional) [session driver](https://docs.astro.build/en/reference/configuration-reference/#sessiondriver) to allow users to log in or log out > [!IMPORTANT] > `deno` requires a workaround due to a CJS/ESM import issue within -> `@atproto/oauth-client-node`. +> `@atproto/oauth-client-node`. For now, avoid using `deno` and use other package managers. -// TODO: we can move this in a details tab +> [!IMPORTANT] +> Using either `localStorage` or `sessionStorage` will result in a ["Session storage could not be initialized." error](https://docs.astro.build/en/reference/errors/session-storage-init-error/) (and is considered insecure for handling sessions anyway). Consider other options, like a database. Requires some familiarity with Astro, but if you want to jump in head first: -1. Install Astro by [following their official - tutorial](https://docs.astro.build/en/install-and-setup/#install-from-the-cli-wizard). - Once you do, [set your Astro site to server - mode](https://docs.astro.build/en/guides/on-demand-rendering/#server-mode). -2. Install [any of the - adapters](https://docs.astro.build/en/guides/on-demand-rendering/#server-adapters). - -- You can start out with - [Node](https://docs.astro.build/en/guides/integrations-guide/node/), since - that's a widely supported runtime. +### Automatic Installation -3. Run the following command: - -```bash -npm install @fujocoded/authproto -``` +1. Run the following command: ```bash npx astro add @fujocoded/authproto ``` -4. Add the integration to your `astro.config.mjs` file, like this: +This will automatically install `@fujocoded/authproto` and add the integration to your `astro.config.mjs` file. + +> [!TIP] +> +> You can take a look at all the [possible configuration options below](#configuration-options). -// TODO: add a note that this requires a server and an adapter that supports // -some type of storage...? I'm unsure how it works on e.g. netlify for the // -various session handlers +### Manual Installation -// TODO: we might also want to make sure people do not set certain adapters // -or even better just disallow the ones they shouldn't. +1. Run the following command: -```typescript +```bash +npm add @fujocoded/authproto +``` + +2. Add the integration to your `astro.config.mjs` file, like this: + +```js import { defineConfig } from "astro/config"; -+ import node from "@astrojs/node"; +import node from "@astrojs/node"; + import authproto from "@fujocoded/authproto"; export default defineConfig({ - output: "server", -+ adapter: node({ mode: "standalone" }), // ... or whichever adapter you're using! + output: "server", // you can read up more how this works here: https://docs.astro.build/en/guides/on-demand-rendering/ + adapter: node({ mode: "standalone" }), // ... or whichever adapter you're using! + integrations: [ + authproto({ + // config options here @@ -123,12 +121,15 @@ export default defineConfig({ }); ``` -> [!TIP] You can take a look at all the [possible configuration options -> below](#configuration-options). +> [!TIP] +> +> You can take a look at all the [possible configuration options below](#configuration-options). -5. Add the `` component to your site, like this: +# Using `@fujocoded/authproto` -``` +Add the `` component to your site, like this: + +```jsx // src/pages/index.astro --- import { Login } from "@fujocoded/authproto/components"; @@ -137,9 +138,9 @@ import { Login } from "@fujocoded/authproto/components"; ``` -> [!TIP] You might run into a naming collision issue if you also have a page -> named `login`. You can fix this by replacing `{ Login }` with `{ Login as -LoginComponent }`. +> [!TIP] +> +> You might run into a naming collision issue if you also have a page named `login`. You can fix this by replacing `{ Login }` with `{ Login as LoginComponent }`. It'll look like a plain form: @@ -147,7 +148,7 @@ It'll look like a plain form: To make a page only visible to logged in users: -```ts +```jsx // src/pages/secret.astro --- const loggedInUser = Astro.locals.loggedInUser; @@ -168,10 +169,7 @@ if (!loggedInUser) { # Okay how do I _actually_ do stuff with this? -Check out the example sites included: - -- [`__example__`](./__example__) shows you how to set up a login flow. -- `__example_status__` has some examples of creating new records on a PDS. +Check out the example sites included under the [examples folder](./__examples__/). # Configuration options @@ -182,18 +180,12 @@ Check out the example sites included: - `defaultDevUser`, optional. The default handle that gets filled out in the `` component during development. - `driver`, optional. The driver used to store data about OAuth sessions. This - takes Astro's [session driver - options](https://docs.astro.build/en/reference/configuration-reference/#sessiondriver). + takes Astro's [session driver options](https://docs.astro.build/en/reference/configuration-reference/#sessiondriver). You can also set this with `name: "astro:db"` to utilize [Astro's DB integration](https://docs.astro.build/en/guides/integrations-guide/db/) for OAuth sessions. This will set up tables for sessions in your database. - NOTE: The default driver is `memory`. This is fine for development, but it's recommended that you switch to a more reliable solution for production. - - NOTE: Using either `localStorage` or `sessionStorage` will result in a - ["Session storage could not be initialized." - error](https://docs.astro.build/en/reference/errors/session-storage-init-error/) - (and is considered insecure for handling sessions anyway). Consider other - options, like a database. - `scopes`, optional. By default, only the `"atproto"` scope is added. This scope is included with any other scope that's enabled. See [ATproto's documentation for OAuth diff --git a/astro-authproto/__examples__/auth-only-pages/astro.config.mjs b/astro-authproto/__examples__/auth-only-pages/astro.config.mjs index 8d476d7..97ca35e 100644 --- a/astro-authproto/__examples__/auth-only-pages/astro.config.mjs +++ b/astro-authproto/__examples__/auth-only-pages/astro.config.mjs @@ -1,7 +1,6 @@ // @ts-check import { defineConfig } from "astro/config"; import authProto from "@fujocoded/authproto"; -import db from "@astrojs/db"; // https://astro.build/config export default defineConfig({ @@ -11,9 +10,6 @@ export default defineConfig({ }, integrations: [ authProto({ - // driver: { - // name: "astro:db", - // }, applicationName: "Authproto test", applicationDomain: "fujocoded.com", defaultDevUser: "essentialrandom.bsky.social", @@ -23,6 +19,5 @@ export default defineConfig({ additionalScopes: ["transition:generic"], }, }), - // db(), ], }); diff --git a/astro-authproto/__examples__/auth-only-pages/package-lock.json b/astro-authproto/__examples__/auth-only-pages/package-lock.json index a61318d..1b9723a 100644 --- a/astro-authproto/__examples__/auth-only-pages/package-lock.json +++ b/astro-authproto/__examples__/auth-only-pages/package-lock.json @@ -8,7 +8,6 @@ "name": "example", "version": "0.0.1", "dependencies": { - "@astrojs/db": "^0.17.2", "@astrojs/node": "^9.4.0", "@atproto/api": "^0.17.2", "@fujocoded/authproto": "file:..", @@ -38,40 +37,6 @@ "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-2.12.2.tgz", "integrity": "sha512-w2zfvhjNCkNMmMMOn5b0J8+OmUaBL1o40ipMvqcG6NRpdC+lKxmTi48DT8Xw0SzJ3AfmeFLB45zXZXtmbsjcgw==" }, - "node_modules/@astrojs/db": { - "version": "0.17.2", - "resolved": "https://registry.npmjs.org/@astrojs/db/-/db-0.17.2.tgz", - "integrity": "sha512-rFkw8Cj/kLwr63n1bS/sUw3hNywyvTkPZbKCdwAqd9FfbH3LdN+dH29XwmBC0NhXOxK3wA1jZBRsOOxpcVkV5w==", - "license": "MIT", - "dependencies": { - "@libsql/client": "^0.15.14", - "deep-diff": "^1.0.2", - "drizzle-orm": "^0.42.0", - "kleur": "^4.1.5", - "nanoid": "^5.1.5", - "prompts": "^2.4.2", - "yargs-parser": "^21.1.1", - "zod": "^3.25.76" - } - }, - "node_modules/@astrojs/db/node_modules/nanoid": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.1.5.tgz", - "integrity": "sha512-Ir/+ZpE9fDsNH0hQ3C68uyThDXzYcim2EqcZ8zn8Chtt1iylPT9xXJB0kPCnqzgcEGikO9RxSrh63MsmVCU7Fw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "license": "MIT", - "bin": { - "nanoid": "bin/nanoid.js" - }, - "engines": { - "node": "^18 || >=20" - } - }, "node_modules/@astrojs/internal-helpers": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/@astrojs/internal-helpers/-/internal-helpers-0.7.1.tgz", @@ -1005,200 +970,6 @@ "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==" }, - "node_modules/@libsql/client": { - "version": "0.15.15", - "resolved": "https://registry.npmjs.org/@libsql/client/-/client-0.15.15.tgz", - "integrity": "sha512-twC0hQxPNHPKfeOv3sNT6u2pturQjLcI+CnpTM0SjRpocEGgfiZ7DWKXLNnsothjyJmDqEsBQJ5ztq9Wlu470w==", - "license": "MIT", - "dependencies": { - "@libsql/core": "^0.15.14", - "@libsql/hrana-client": "^0.7.0", - "js-base64": "^3.7.5", - "libsql": "^0.5.22", - "promise-limit": "^2.7.0" - } - }, - "node_modules/@libsql/core": { - "version": "0.15.15", - "resolved": "https://registry.npmjs.org/@libsql/core/-/core-0.15.15.tgz", - "integrity": "sha512-C88Z6UKl+OyuKKPwz224riz02ih/zHYI3Ho/LAcVOgjsunIRZoBw7fjRfaH9oPMmSNeQfhGklSG2il1URoOIsA==", - "license": "MIT", - "dependencies": { - "js-base64": "^3.7.5" - } - }, - "node_modules/@libsql/darwin-arm64": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.5.22.tgz", - "integrity": "sha512-4B8ZlX3nIDPndfct7GNe0nI3Yw6ibocEicWdC4fvQbSs/jdq/RC2oCsoJxJ4NzXkvktX70C1J4FcmmoBy069UA==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@libsql/darwin-x64": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.5.22.tgz", - "integrity": "sha512-ny2HYWt6lFSIdNFzUFIJ04uiW6finXfMNJ7wypkAD8Pqdm6nAByO+Fdqu8t7sD0sqJGeUCiOg480icjyQ2/8VA==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@libsql/hrana-client": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@libsql/hrana-client/-/hrana-client-0.7.0.tgz", - "integrity": "sha512-OF8fFQSkbL7vJY9rfuegK1R7sPgQ6kFMkDamiEccNUvieQ+3urzfDFI616oPl8V7T9zRmnTkSjMOImYCAVRVuw==", - "license": "MIT", - "dependencies": { - "@libsql/isomorphic-fetch": "^0.3.1", - "@libsql/isomorphic-ws": "^0.1.5", - "js-base64": "^3.7.5", - "node-fetch": "^3.3.2" - } - }, - "node_modules/@libsql/hrana-client/node_modules/node-fetch": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", - "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", - "license": "MIT", - "dependencies": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/node-fetch" - } - }, - "node_modules/@libsql/isomorphic-fetch": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@libsql/isomorphic-fetch/-/isomorphic-fetch-0.3.1.tgz", - "integrity": "sha512-6kK3SUK5Uu56zPq/Las620n5aS9xJq+jMBcNSOmjhNf/MUvdyji4vrMTqD7ptY7/4/CAVEAYDeotUz60LNQHtw==", - "license": "MIT", - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@libsql/isomorphic-ws": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz", - "integrity": "sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg==", - "license": "MIT", - "dependencies": { - "@types/ws": "^8.5.4", - "ws": "^8.13.0" - } - }, - "node_modules/@libsql/linux-arm-gnueabihf": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm-gnueabihf/-/linux-arm-gnueabihf-0.5.22.tgz", - "integrity": "sha512-3Uo3SoDPJe/zBnyZKosziRGtszXaEtv57raWrZIahtQDsjxBVjuzYQinCm9LRCJCUT5t2r5Z5nLDPJi2CwZVoA==", - "cpu": [ - "arm" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@libsql/linux-arm-musleabihf": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm-musleabihf/-/linux-arm-musleabihf-0.5.22.tgz", - "integrity": "sha512-LCsXh07jvSojTNJptT9CowOzwITznD+YFGGW+1XxUr7fS+7/ydUrpDfsMX7UqTqjm7xG17eq86VkWJgHJfvpNg==", - "cpu": [ - "arm" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@libsql/linux-arm64-gnu": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.5.22.tgz", - "integrity": "sha512-KSdnOMy88c9mpOFKUEzPskSaF3VLflfSUCBwas/pn1/sV3pEhtMF6H8VUCd2rsedwoukeeCSEONqX7LLnQwRMA==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@libsql/linux-arm64-musl": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.5.22.tgz", - "integrity": "sha512-mCHSMAsDTLK5YH//lcV3eFEgiR23Ym0U9oEvgZA0667gqRZg/2px+7LshDvErEKv2XZ8ixzw3p1IrBzLQHGSsw==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@libsql/linux-x64-gnu": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.5.22.tgz", - "integrity": "sha512-kNBHaIkSg78Y4BqAdgjcR2mBilZXs4HYkAmi58J+4GRwDQZh5fIUWbnQvB9f95DkWUIGVeenqLRFY2pcTmlsew==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@libsql/linux-x64-musl": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.5.22.tgz", - "integrity": "sha512-UZ4Xdxm4pu3pQXjvfJiyCzZop/9j/eA2JjmhMaAhe3EVLH2g11Fy4fwyUp9sT1QJYR1kpc2JLuybPM0kuXv/Tg==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@libsql/win32-x64-msvc": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.5.22.tgz", - "integrity": "sha512-Fj0j8RnBpo43tVZUVoNK6BV/9AtDUM5S7DF3LB4qTYg1LMSZqi3yeCneUTLJD6XomQJlZzbI4mst89yspVSAnA==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "win32" - ] - }, - "node_modules/@neon-rs/load": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/@neon-rs/load/-/load-0.0.4.tgz", - "integrity": "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw==", - "license": "MIT" - }, "node_modules/@oslojs/encoding": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@oslojs/encoding/-/encoding-1.1.0.tgz", @@ -1601,15 +1372,6 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==" }, - "node_modules/@types/ws": { - "version": "8.18.1", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz", - "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==", - "license": "MIT", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@ungap/structured-clone": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz", @@ -2137,15 +1899,6 @@ "node": ">=4" } }, - "node_modules/data-uri-to-buffer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", - "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", - "license": "MIT", - "engines": { - "node": ">= 12" - } - }, "node_modules/debug": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", @@ -2174,12 +1927,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/deep-diff": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-1.0.2.tgz", - "integrity": "sha512-aWS3UIVH+NPGCD1kki+DCU9Dua032iSsO43LqQpcs4R3+dVv7tX0qBGjiVHJHjplsoUM2XRO/KB92glqc68awg==", - "license": "MIT" - }, "node_modules/defu": { "version": "6.1.4", "resolved": "https://registry.npmjs.org/defu/-/defu-6.1.4.tgz", @@ -2261,127 +2008,6 @@ "resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz", "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==" }, - "node_modules/drizzle-orm": { - "version": "0.42.0", - "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.42.0.tgz", - "integrity": "sha512-pS8nNJm2kBNZwrOjTHJfdKkaU+KuUQmV/vk5D57NojDq4FG+0uAYGMulXtYT///HfgsMF0hnFFvu1ezI3OwOkg==", - "license": "Apache-2.0", - "peerDependencies": { - "@aws-sdk/client-rds-data": ">=3", - "@cloudflare/workers-types": ">=4", - "@electric-sql/pglite": ">=0.2.0", - "@libsql/client": ">=0.10.0", - "@libsql/client-wasm": ">=0.10.0", - "@neondatabase/serverless": ">=0.10.0", - "@op-engineering/op-sqlite": ">=2", - "@opentelemetry/api": "^1.4.1", - "@planetscale/database": ">=1.13", - "@prisma/client": "*", - "@tidbcloud/serverless": "*", - "@types/better-sqlite3": "*", - "@types/pg": "*", - "@types/sql.js": "*", - "@vercel/postgres": ">=0.8.0", - "@xata.io/client": "*", - "better-sqlite3": ">=7", - "bun-types": "*", - "expo-sqlite": ">=14.0.0", - "gel": ">=2", - "knex": "*", - "kysely": "*", - "mysql2": ">=2", - "pg": ">=8", - "postgres": ">=3", - "sql.js": ">=1", - "sqlite3": ">=5" - }, - "peerDependenciesMeta": { - "@aws-sdk/client-rds-data": { - "optional": true - }, - "@cloudflare/workers-types": { - "optional": true - }, - "@electric-sql/pglite": { - "optional": true - }, - "@libsql/client": { - "optional": true - }, - "@libsql/client-wasm": { - "optional": true - }, - "@neondatabase/serverless": { - "optional": true - }, - "@op-engineering/op-sqlite": { - "optional": true - }, - "@opentelemetry/api": { - "optional": true - }, - "@planetscale/database": { - "optional": true - }, - "@prisma/client": { - "optional": true - }, - "@tidbcloud/serverless": { - "optional": true - }, - "@types/better-sqlite3": { - "optional": true - }, - "@types/pg": { - "optional": true - }, - "@types/sql.js": { - "optional": true - }, - "@vercel/postgres": { - "optional": true - }, - "@xata.io/client": { - "optional": true - }, - "better-sqlite3": { - "optional": true - }, - "bun-types": { - "optional": true - }, - "expo-sqlite": { - "optional": true - }, - "gel": { - "optional": true - }, - "knex": { - "optional": true - }, - "kysely": { - "optional": true - }, - "mysql2": { - "optional": true - }, - "pg": { - "optional": true - }, - "postgres": { - "optional": true - }, - "prisma": { - "optional": true - }, - "sql.js": { - "optional": true - }, - "sqlite3": { - "optional": true - } - } - }, "node_modules/dset": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/dset/-/dset-3.1.4.tgz", @@ -2524,29 +2150,6 @@ } } }, - "node_modules/fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "paypal", - "url": "https://paypal.me/jimmywarting" - } - ], - "license": "MIT", - "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - }, - "engines": { - "node": "^12.20 || >= 14.13" - } - }, "node_modules/flattie": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/flattie/-/flattie-1.1.1.tgz", @@ -2580,18 +2183,6 @@ "unicode-trie": "^2.0.0" } }, - "node_modules/formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "license": "MIT", - "dependencies": { - "fetch-blob": "^3.1.2" - }, - "engines": { - "node": ">=12.20.0" - } - }, "node_modules/fresh": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", @@ -2967,12 +2558,6 @@ "integrity": "sha512-yLEMkBbLZTlVQqOnQ4FiMujR6T4DEcCb1xizmvXS+OxuhwcbtynoosRzdMA69zZCShCNAbi+gJ71FxZBBXx1SA==", "license": "MIT" }, - "node_modules/js-base64": { - "version": "3.7.8", - "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.8.tgz", - "integrity": "sha512-hNngCeKxIUQiEUN3GPJOkz4wF/YvdUdbNL9hsBcMQTkKzboD7T/q3OYOuuPZLUE6dBxSGpwhk5mwuDud7JVAow==", - "license": "BSD-3-Clause" - }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -2992,47 +2577,6 @@ "node": ">=6" } }, - "node_modules/libsql": { - "version": "0.5.22", - "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.5.22.tgz", - "integrity": "sha512-NscWthMQt7fpU8lqd7LXMvT9pi+KhhmTHAJWUB/Lj6MWa0MKFv0F2V4C6WKKpjCVZl0VwcDz4nOI3CyaT1DDiA==", - "cpu": [ - "x64", - "arm64", - "wasm32", - "arm" - ], - "license": "MIT", - "os": [ - "darwin", - "linux", - "win32" - ], - "dependencies": { - "@neon-rs/load": "^0.0.4", - "detect-libc": "2.0.2" - }, - "optionalDependencies": { - "@libsql/darwin-arm64": "0.5.22", - "@libsql/darwin-x64": "0.5.22", - "@libsql/linux-arm-gnueabihf": "0.5.22", - "@libsql/linux-arm-musleabihf": "0.5.22", - "@libsql/linux-arm64-gnu": "0.5.22", - "@libsql/linux-arm64-musl": "0.5.22", - "@libsql/linux-x64-gnu": "0.5.22", - "@libsql/linux-x64-musl": "0.5.22", - "@libsql/win32-x64-msvc": "0.5.22" - } - }, - "node_modules/libsql/node_modules/detect-libc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", - "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", - "license": "Apache-2.0", - "engines": { - "node": ">=8" - } - }, "node_modules/longest-streak": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz", @@ -3901,26 +3445,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "deprecated": "Use your platform's native DOMException instead", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "license": "MIT", - "engines": { - "node": ">=10.5.0" - } - }, "node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -4128,12 +3652,6 @@ "node": ">=6" } }, - "node_modules/promise-limit": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/promise-limit/-/promise-limit-2.7.0.tgz", - "integrity": "sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==", - "license": "ISC" - }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -5158,15 +4676,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/web-streams-polyfill": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", - "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", - "license": "MIT", - "engines": { - "node": ">= 8" - } - }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", @@ -5219,27 +4728,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/ws": { - "version": "8.18.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", - "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", - "license": "MIT", - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": ">=5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, "node_modules/xxhash-wasm": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.1.0.tgz", diff --git a/astro-authproto/__examples__/auth-only-pages/package.json b/astro-authproto/__examples__/auth-only-pages/package.json index 5e40716..42865ec 100644 --- a/astro-authproto/__examples__/auth-only-pages/package.json +++ b/astro-authproto/__examples__/auth-only-pages/package.json @@ -10,7 +10,6 @@ "astro": "astro" }, "dependencies": { - "@astrojs/db": "^0.17.2", "@astrojs/node": "^9.4.0", "@atproto/api": "^0.17.2", "@fujocoded/authproto": "file:..", diff --git a/astro-authproto/__examples__/read-write-records/README.md b/astro-authproto/__examples__/read-write-records/README.md index 3a19ef0..0a00291 100644 --- a/astro-authproto/__examples__/read-write-records/README.md +++ b/astro-authproto/__examples__/read-write-records/README.md @@ -1,40 +1,32 @@ -# How to use `@fujocoded/authproto` in practice! +# How to read and write records with `@fujocoded/authproto` -## Before you start - -1. Other than `@fujocoded/authproto`, you'll also need `@atproto/api` and `@atproto/common-web` to use the code in this example. You can install it with: - -```bash -npm install @atproto/api @atproto/common-web -``` - -> [!NOTE] -> You'll need to set your OAuth scopes accordingly. `genericData` should be set to true under the `scopes` configuration option. - -2. You'll also need to create an agent, which will essentially interact with atproto for you. Most of the needed atproto libraries should already be included with the integration. See [`src/lib/atproto.ts`](./src/lib/atproto.ts) for the full code. - -[The previous example](../__example__) showed how to log in and log out a user using `@fujocoded/authproto`. This example will show you show to create and list records. This will involve: +This will involve: -- Creating an ATproto agent, which will interact with ATproto on your behalf. After following the [before you start](#before-you-start) section, you can check out (or copy) [`src/lib/atproto.ts`](./src/lib/atproto.ts) to see how to create the agent. -- Use the ATproto agent to [list records from a collection](./src/components/Status.astro). + +- Use the ATproto agent to [list records from a collection](./src/components/ListStatuses.astro). - Pairing the ATproto agent with Astro actions to [create new records in a collections](./src/actions/index.ts). > [!NOTE] > To create, update, and delete records in your PDS, you'll need to set your OAuth scopes accordingly. `genericData` should be set to true under the `scopes` configuration option. -## In this example +## Before you start -For this example, we'll do a status update. You can write text and then display them on your PDS. +Other than `@fujocoded/authproto`, you'll also need `@atproto/api` and `@atproto/common-web` to use the code in this example. You can install it with: -![A simple form with a textbox that says 'happy! ^^'](./assets/form.png) +```bash +npm install @atproto/api @atproto/common-web +``` -You can use [PDSls](https://pdsls.dev/) to test it out! Search by the handle you used to log in. -For this example, we'll do a status update. You can write text and then display them on your PDS. See [`src/actions/index.ts`](./src/actions/index.ts) for the code. +## Getting started -4. To actually see if this works, let's make a form. You can see how this is done in [`src/pages/status.astro`](./src/pages/status.astro). (It also has an example of how to display all the statuses made by the logged in user. Great for a semi-private diary!) +For this example, we'll do a status update. You can write text and then display them on your PDS. See [`src/actions/index.ts`](./src/actions/index.ts) for the code. There's a form in [`src/components/PostStatus.astro`](./src/components/PostStatus.astro) that includes the example Astro Action. -![A screenshot of the PDSls service where a record for 'xyz.statuscity.status' has been made](./assets/result.png) +![A simple form with a textbox that says 'happy! ^^'](./assets/form.png) + +You can see how statuses are listed in [`src/components/ListStatuses.astro`](./src/components/ListStatuses.astro). ![A screenshot of the resulting statuses show up on the Astro demo website](./assets/display_result.png) -5. Then hit post to see if it shows up. You can use [PDSls](https://pdsls.dev/) to test it out! Search by the handle you used to log in. +You can use [PDSls](https://pdsls.dev/) to see it live on ATProto! Search by the handle you used to log in. + +![A screenshot of the PDSls service where a record for 'xyz.statuscity.status' has been made](./assets/result.png) diff --git a/astro-authproto/__examples__/read-write-records/src/actions/index.ts b/astro-authproto/__examples__/read-write-records/src/actions/index.ts index 6163c05..ac8bd1d 100644 --- a/astro-authproto/__examples__/read-write-records/src/actions/index.ts +++ b/astro-authproto/__examples__/read-write-records/src/actions/index.ts @@ -20,10 +20,9 @@ export const server = { }); } - // Since we need to write, the agent needs to the information - // of the logged in user. - // TODO: explain better - const agent = await getPdsAgent({ loggedInUser }); // this is needed to make requests to atproto + // getPdsAgent is an authorized agent that talks with ATProto + // using the PDS for the `loggedInUser` provided by @fujocoded/authproto + const agent = await getPdsAgent({ loggedInUser }); if (!agent) { throw new ActionError({ diff --git a/astro-authproto/src/components/Login.astro b/astro-authproto/src/components/Login.astro index 202c0e3..c934ffb 100644 --- a/astro-authproto/src/components/Login.astro +++ b/astro-authproto/src/components/Login.astro @@ -2,29 +2,30 @@ import { defaultDevUser } from "fujocoded:authproto/config"; interface Props { + class?: string; /** Optional redirect URL after successful login/logout */ redirect?: string; } -const { redirect: redirectUrl } = Astro.props; const currentUser = Astro.locals.loggedInUser; - -const { class: cssClass, 'class:list': cssClassList } = Astro.props; +const { class: cssClass, redirect: redirectUrl, ...rest } = Astro.props; --- { currentUser ? ( // If there's a current user, show the log out button -
+ {redirectUrl && }
) : ( // If there's no current user, show the login button -
+ {redirectUrl && }