hono-atcute
v0.0.10
Published
A starter for creating a TypeScript package.
Readme
hono-atcute
Hono middleware for managing authenticated atcute clients.
Getting Started
Install
npm i hono-atcuteCloudflare stores
If deploying to Cloudflare, export and configure the AtprotoStore DurableObject:
export { AtprotoStore } from "hono-atcute/cloudflare";{
"$schema": "./node_modules/wrangler/config-schema.json",
// ...
"durable_objects": {
"bindings": [
{
"class_name": "AtprotoStore",
"name": "ATPROTO_STORE",
},
],
},
"migrations": [
{
"tag": "v1",
"new_classes": ["AtprotoStore"],
},
],
}Add middleware and callback
import { atcute, scope } from "hono-atcute";
import { createStores } from "hono-atcute/cloudflare";
app.use(
atcute({
localdev: import.meta.env.DEV,
callbackPath: "/oauth/callback",
scope: () => [scope.rpc({ lxm: ["app.bsky.actor.getProfile"], aud: "*" })],
stores: (c) => createStores(c.env.ATPROTO_STORE),
}),
);
app.get("/oauth/callback", async (c) => {
const atcute = c.get("atcute");
try {
const result = await atcute.oauth.callback(new URL(c.req.url).searchParams);
await setSessionDid(c, result.session.did);
return c.redirect(new URL("/", c.req.url));
} catch {
return c.redirect(new URL(`/?error=${encodeURI("Failed to login")}`, c.req.url));
}
});Contributing
- Install dependencies:
vp install- Run the unit tests:
vp test- Build the library:
vp pack