Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions astro-authproto/__example_status__/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# jetbrains setting folder
.idea/
30 changes: 30 additions & 0 deletions astro-authproto/__example_status__/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# How to use `@fujocoded/authproto` in practice!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do first a broad introduction to the repo/example, and set the scene for the more detailed explanation.

  1. What to expect from this example. Quick take: This directory shows how to use @fujocoded/authproto to create and list your very own ATproto records! It builds on the simpler login example in [...], and assumes you're already familiar with that code.

  2. How to use this repo. You can follow along the explanation below to walk the code together [note: I assume this is how you mean for it to be used], or jump straight into the action by looking at src/pages/status.astro (for how to list records) or src/actions/index.ts (for how to create records).

This is a great time to make sure you add a warning about "make sure you set scopes.genericData to true" if you want to create a record.

Then, you can go further into the explanation.

## Before you start

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing you might have noticed above: I swapped the position of reading and writing in your form. I think this is going to be easier to follow along with, but it means the first time this runs there won't be any status to show. An easy way to fix this is to add a couple statuses in the FujoCoded PDS and display those too, like:


Latest FujoVerse statuses

fujocoded.bsky.social says: "sure hope you'd support me on Patreon"
fujoweb.dev says: "catboys are hot"

Your statuses

You have no statuses. (or) Log in to create your own!


Let me know what you think. I don't want to make you do more work than necessary, but it's fairly quick to do if it's a good idea. It also shows you don't need to be logged in to do things like read statuses of random people.

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
```

## In this example

[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:

- 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).
- 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.

For this example, we'll do a status update. You can write text and then display them on your PDS.

![A simple form with a textbox that says 'happy! ^^'](./assets/form.png)

You can use [PDSls](https://pdsls.dev/) to test it out! 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)

![A screenshot of the resulting statuses show up on the Astro demo website](./assets/display_result.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions astro-authproto/__example_status__/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can likely just do astro.config.mts and get the checks automatically. Don't quote me on that. I'm fairly sure it autochecks on my .mjs files? Maybe it's a VSCode setting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have VSCode and it autochecks on .mjs files. I think the // @ts-check gets included when you first spin up an Astro site. Should I get rid of it anyway?

import { defineConfig } from "astro/config";
import authProto from "@fujocoded/authproto";

// https://astro.build/config
export default defineConfig({
output: "server",
session: {
driver: "memory",
},
integrations: [
authProto({
applicationName: "Authproto test",
applicationDomain: "fujocoded.com",
defaultDevUser: "essentialrandom.bsky.social",
scopes: {
genericData: true, // this is needed to create, update, or delete records from a PDS
},
}),
],
});
Loading