-
Notifications
You must be signed in to change notification settings - Fork 2
add another example site for @fujocoded/authproto #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
63b4ca0
f02a04d
b7eac4d
cbaeab5
2fbfa95
26ff6f3
46d1af5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# How to use `@fujocoded/authproto` in practice! | ||
|
||
## Before you start | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 statusesfujocoded.bsky.social says: "sure hope you'd support me on Patreon" Your statusesYou 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. | ||
|
||
 | ||
|
||
You can use [PDSls](https://pdsls.dev/) to test it out! Search by the handle you used to log in. | ||
|
||
 | ||
|
||
 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @ts-check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can likely just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also have VSCode and it autochecks on |
||
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 | ||
}, | ||
}), | ||
], | ||
}); |
There was a problem hiding this comment.
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.
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.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) orsrc/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.