A minimal starter for ATProto logins in Astro

Compare changes

Choose any two refs to compare.

+48 -17
README.md
···
-
# Astro Starter Kit: Minimal
+
# Astro ATProto OAuth Starter
+
+
A minimal [Astro](https://astro.build) starter template demonstrating OAuth authentication with AT Protocol (ATProto), the decentralized social networking protocol used by Bluesky and other services.
+
+
This starter includes:
+
- Complete OAuth authentication flow using `@atproto/oauth-client-node`
+
- Cookie-based session management
+
- Profile display after authentication
+
- Login/logout endpoints
+
- Tailwind CSS and DaisyUI styling
+
+
## ๐Ÿš€ Getting Started
+
+
1. **Install dependencies:**
+
```sh
+
npm install
+
```
-
```sh
-
npm create astro@latest -- --template minimal
-
```
+
2. **Configure environment variables:**
+
```sh
+
cp .env.template .env
+
```
+
Edit `.env` if you need to change the port (default: 4321) or set a public URL.
-
> ๐Ÿง‘โ€๐Ÿš€ **Seasoned astronaut?** Delete this file. Have fun!
+
3. **Start the development server:**
+
```sh
+
npm run dev
+
```
+
The app will be available at `http://localhost:4321`
-
## ๐Ÿš€ Project Structure
+
4. **Try logging in:**
+
Enter your AT Protocol handle (e.g., `alice.bsky.social`) to authenticate.
-
Inside of your Astro project, you'll see the following folders and files:
+
## ๐Ÿ“ Project Structure
```text
/
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ src/
-
โ”‚ โ””โ”€โ”€ pages/
-
โ”‚ โ””โ”€โ”€ index.astro
+
โ”‚ โ”œโ”€โ”€ lib/
+
โ”‚ โ”‚ โ”œโ”€โ”€ context.ts # OAuth client singleton
+
โ”‚ โ”‚ โ”œโ”€โ”€ oauth.ts # OAuth client configuration
+
โ”‚ โ”‚ โ”œโ”€โ”€ session.ts # Session management
+
โ”‚ โ”‚ โ””โ”€โ”€ storage.ts # Cookie-based stores
+
โ”‚ โ”œโ”€โ”€ pages/
+
โ”‚ โ”‚ โ”œโ”€โ”€ api/
+
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ login.ts # Login endpoint
+
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ logout.ts # Logout endpoint
+
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ oauth/
+
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ callback.ts # OAuth callback handler
+
โ”‚ โ”‚ โ””โ”€โ”€ index.astro # Main page with login UI
+
โ”‚ โ””โ”€โ”€ styles.css
โ””โ”€โ”€ package.json
```
-
-
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
-
-
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
-
-
Any static assets, like images, can be placed in the `public/` directory.
## ๐Ÿงž Commands
···
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |
-
## ๐Ÿ‘€ Want to learn more?
+
## ๐Ÿ“š Learn More
-
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
+
- [Astro Documentation](https://docs.astro.build)
+
- [AT Protocol Documentation](https://atproto.com)
+
- [@atproto/oauth-client-node](https://github.com/bluesky-social/atproto/tree/main/packages/oauth/oauth-client-node)
+
- [Bluesky](https://bsky.app)
+145 -309
package-lock.json
···
"version": "0.0.1",
"dependencies": {
"@astrojs/node": "^9.5.0",
-
"@astrojs/tailwind": "^6.0.2",
"@atproto/api": "^0.17.4",
"@atproto/oauth-client-node": "^0.3.10",
"@tailwindcss/vite": "^4.1.16",
···
},
"engines": {
"node": "18.20.8 || ^20.3.0 || >=22.0.0"
-
}
-
},
-
"node_modules/@astrojs/tailwind": {
-
"version": "6.0.2",
-
"resolved": "https://registry.npmjs.org/@astrojs/tailwind/-/tailwind-6.0.2.tgz",
-
"integrity": "sha512-j3mhLNeugZq6A8dMNXVarUa8K6X9AW+QHU9u3lKNrPLMHhOQ0S7VeWhHwEeJFpEK1BTKEUY1U78VQv2gN6hNGg==",
-
"license": "MIT",
-
"dependencies": {
-
"autoprefixer": "^10.4.21",
-
"postcss": "^8.5.3",
-
"postcss-load-config": "^4.0.2"
-
},
-
"peerDependencies": {
-
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0",
-
"tailwindcss": "^3.0.24"
}
},
"node_modules/@astrojs/telemetry": {
···
}
},
"node_modules/@atproto/api": {
-
"version": "0.17.4",
-
"resolved": "https://registry.npmjs.org/@atproto/api/-/api-0.17.4.tgz",
-
"integrity": "sha512-MRa0WdxyDiGF7fVKd/2ldvonsHQjsaLUOGw/PHrZ7J01lqlw/jaXLS25FNNYzjPGmGpnIyDCIg4Uucd/OblI9w==",
+
"version": "0.17.6",
+
"resolved": "https://registry.npmjs.org/@atproto/api/-/api-0.17.6.tgz",
+
"integrity": "sha512-0iYCD8+LOsHjHjwJcqGPfJN/h4b+IpU3GjOV0TSLk0XdCaxpHBKNu3wgCJVst4DhVjXcgsr2qQoRZ3Jja2LupA==",
"license": "MIT",
"dependencies": {
"@atproto/common-web": "^0.4.3",
···
},
"node_modules/@shikijs/core": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.13.0.tgz",
-
"integrity": "sha512-3P8rGsg2Eh2qIHekwuQjzWhKI4jV97PhvYjYUzGqjvJfqdQPz+nMlfWahU24GZAyW1FxFI1sYjyhfh5CoLmIUA==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.14.0.tgz",
+
"integrity": "sha512-qRSeuP5vlYHCNUIrpEBQFO7vSkR7jn7Kv+5X3FO/zBKVDGQbcnlScD3XhkrHi/R8Ltz0kEjvFR9Szp/XMRbFMw==",
"license": "MIT",
"dependencies": {
-
"@shikijs/types": "3.13.0",
+
"@shikijs/types": "3.14.0",
"@shikijs/vscode-textmate": "^10.0.2",
"@types/hast": "^3.0.4",
"hast-util-to-html": "^9.0.5"
},
"node_modules/@shikijs/engine-javascript": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-3.13.0.tgz",
-
"integrity": "sha512-Ty7xv32XCp8u0eQt8rItpMs6rU9Ki6LJ1dQOW3V/56PKDcpvfHPnYFbsx5FFUP2Yim34m/UkazidamMNVR4vKg==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-3.14.0.tgz",
+
"integrity": "sha512-3v1kAXI2TsWQuwv86cREH/+FK9Pjw3dorVEykzQDhwrZj0lwsHYlfyARaKmn6vr5Gasf8aeVpb8JkzeWspxOLQ==",
"license": "MIT",
"dependencies": {
-
"@shikijs/types": "3.13.0",
+
"@shikijs/types": "3.14.0",
"@shikijs/vscode-textmate": "^10.0.2",
"oniguruma-to-es": "^4.3.3"
},
"node_modules/@shikijs/engine-oniguruma": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.13.0.tgz",
-
"integrity": "sha512-O42rBGr4UDSlhT2ZFMxqM7QzIU+IcpoTMzb3W7AlziI1ZF7R8eS2M0yt5Ry35nnnTX/LTLXFPUjRFCIW+Operg==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.14.0.tgz",
+
"integrity": "sha512-TNcYTYMbJyy+ZjzWtt0bG5y4YyMIWC2nyePz+CFMWqm+HnZZyy9SWMgo8Z6KBJVIZnx8XUXS8U2afO6Y0g1Oug==",
"license": "MIT",
"dependencies": {
-
"@shikijs/types": "3.13.0",
+
"@shikijs/types": "3.14.0",
"@shikijs/vscode-textmate": "^10.0.2"
},
"node_modules/@shikijs/langs": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.13.0.tgz",
-
"integrity": "sha512-672c3WAETDYHwrRP0yLy3W1QYB89Hbpj+pO4KhxK6FzIrDI2FoEXNiNCut6BQmEApYLfuYfpgOZaqbY+E9b8wQ==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.14.0.tgz",
+
"integrity": "sha512-DIB2EQY7yPX1/ZH7lMcwrK5pl+ZkP/xoSpUzg9YC8R+evRCCiSQ7yyrvEyBsMnfZq4eBzLzBlugMyTAf13+pzg==",
"license": "MIT",
"dependencies": {
-
"@shikijs/types": "3.13.0"
+
"@shikijs/types": "3.14.0"
},
"node_modules/@shikijs/themes": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.13.0.tgz",
-
"integrity": "sha512-Vxw1Nm1/Od8jyA7QuAenaV78BG2nSr3/gCGdBkLpfLscddCkzkL36Q5b67SrLLfvAJTOUzW39x4FHVCFriPVgg==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.14.0.tgz",
+
"integrity": "sha512-fAo/OnfWckNmv4uBoUu6dSlkcBc+SA1xzj5oUSaz5z3KqHtEbUypg/9xxgJARtM6+7RVm0Q6Xnty41xA1ma1IA==",
"license": "MIT",
"dependencies": {
-
"@shikijs/types": "3.13.0"
+
"@shikijs/types": "3.14.0"
},
"node_modules/@shikijs/types": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.13.0.tgz",
-
"integrity": "sha512-oM9P+NCFri/mmQ8LoFGVfVyemm5Hi27330zuOBp0annwJdKH1kOLndw3zCtAVDehPLg9fKqoEx3Ht/wNZxolfw==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.14.0.tgz",
+
"integrity": "sha512-bQGgC6vrY8U/9ObG1Z/vTro+uclbjjD/uG58RvfxKZVD5p9Yc1ka3tVyEFy7BNJLzxuWyHH5NWynP9zZZS59eQ==",
"license": "MIT",
"dependencies": {
"@shikijs/vscode-textmate": "^10.0.2",
···
},
"node_modules/@types/node": {
-
"version": "24.9.1",
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.1.tgz",
-
"integrity": "sha512-QoiaXANRkSXK6p0Duvt56W208du4P9Uye9hWLWgGMDTEoKPhuenzNcC4vGUmrNkiOKTlIrBoyNQYNpSwfEZXSg==",
+
"version": "24.9.2",
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.2.tgz",
+
"integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==",
"license": "MIT",
"dependencies": {
"undici-types": "~7.16.0"
···
},
"node_modules/astro": {
-
"version": "5.15.1",
-
"resolved": "https://registry.npmjs.org/astro/-/astro-5.15.1.tgz",
-
"integrity": "sha512-VM679M1qxOjGo6q3vKYDNDddkALGgMopG93IwbEXd3Buc2xVLuuPj4HNziNugSbPQx5S6UReMp5uzw10EJN81A==",
+
"version": "5.15.2",
+
"resolved": "https://registry.npmjs.org/astro/-/astro-5.15.2.tgz",
+
"integrity": "sha512-xQQ+PiYJ7WpUJrHJpAb52TQAUCFmSR8lAtQr3tFfSIZoTQiEMFx3HITJ01t3eDUpHjja8J6JcYqgAhr9xygKQg==",
"license": "MIT",
"dependencies": {
"@astrojs/compiler": "^2.12.2",
···
"unist-util-visit": "^5.0.0",
"unstorage": "^1.17.0",
"vfile": "^6.0.3",
-
"vite": "^6.3.6",
+
"vite": "^6.4.1",
"vitefu": "^1.1.1",
"xxhash-wasm": "^1.1.0",
"yargs-parser": "^21.1.1",
···
"sharp": "^0.34.0"
},
-
"node_modules/autoprefixer": {
-
"version": "10.4.21",
-
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.21.tgz",
-
"integrity": "sha512-O+A6LWV5LDHSJD3LjHYoNi4VLsj/Whi7k6zG12xTYaU4cQ8oxQGckXNX8cRHK5yOZ/ppVHe0ZBXGzSV9jXdVbQ==",
-
"funding": [
-
{
-
"type": "opencollective",
-
"url": "https://opencollective.com/postcss/"
-
},
-
{
-
"type": "tidelift",
-
"url": "https://tidelift.com/funding/github/npm/autoprefixer"
-
},
-
{
-
"type": "github",
-
"url": "https://github.com/sponsors/ai"
-
}
-
],
+
"node_modules/astro/node_modules/vite": {
+
"version": "6.4.1",
+
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
+
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
"license": "MIT",
"dependencies": {
-
"browserslist": "^4.24.4",
-
"caniuse-lite": "^1.0.30001702",
-
"fraction.js": "^4.3.7",
-
"normalize-range": "^0.1.2",
-
"picocolors": "^1.1.1",
-
"postcss-value-parser": "^4.2.0"
+
"esbuild": "^0.25.0",
+
"fdir": "^6.4.4",
+
"picomatch": "^4.0.2",
+
"postcss": "^8.5.3",
+
"rollup": "^4.34.9",
+
"tinyglobby": "^0.2.13"
},
"bin": {
-
"autoprefixer": "bin/autoprefixer"
+
"vite": "bin/vite.js"
},
"engines": {
-
"node": "^10 || ^12 || >=14"
+
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
+
},
+
"funding": {
+
"url": "https://github.com/vitejs/vite?sponsor=1"
+
},
+
"optionalDependencies": {
+
"fsevents": "~2.3.3"
},
"peerDependencies": {
-
"postcss": "^8.1.0"
+
"@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
+
"jiti": ">=1.21.0",
+
"less": "*",
+
"lightningcss": "^1.21.0",
+
"sass": "*",
+
"sass-embedded": "*",
+
"stylus": "*",
+
"sugarss": "*",
+
"terser": "^5.16.0",
+
"tsx": "^4.8.1",
+
"yaml": "^2.4.2"
+
},
+
"peerDependenciesMeta": {
+
"@types/node": {
+
"optional": true
+
},
+
"jiti": {
+
"optional": true
+
},
+
"less": {
+
"optional": true
+
},
+
"lightningcss": {
+
"optional": true
+
},
+
"sass": {
+
"optional": true
+
},
+
"sass-embedded": {
+
"optional": true
+
},
+
"stylus": {
+
"optional": true
+
},
+
"sugarss": {
+
"optional": true
+
},
+
"terser": {
+
"optional": true
+
},
+
"tsx": {
+
"optional": true
+
},
+
"yaml": {
+
"optional": true
+
}
},
"node_modules/await-lock": {
···
],
"license": "MIT"
},
-
"node_modules/baseline-browser-mapping": {
-
"version": "2.8.20",
-
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.20.tgz",
-
"integrity": "sha512-JMWsdF+O8Orq3EMukbUN1QfbLK9mX2CkUmQBcW2T0s8OmdAUL5LLM/6wFwSrqXzlXB13yhyK9gTKS1rIizOduQ==",
-
"license": "Apache-2.0",
-
"bin": {
-
"baseline-browser-mapping": "dist/cli.js"
-
}
-
},
"node_modules/boxen": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/boxen/-/boxen-8.0.1.tgz",
···
"base64-js": "^1.1.2"
},
-
"node_modules/browserslist": {
-
"version": "4.27.0",
-
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.27.0.tgz",
-
"integrity": "sha512-AXVQwdhot1eqLihwasPElhX2tAZiBjWdJ9i/Zcj2S6QYIjkx62OKSfnobkriB81C3l4w0rVy3Nt4jaTBltYEpw==",
-
"funding": [
-
{
-
"type": "opencollective",
-
"url": "https://opencollective.com/browserslist"
-
},
-
{
-
"type": "tidelift",
-
"url": "https://tidelift.com/funding/github/npm/browserslist"
-
},
-
{
-
"type": "github",
-
"url": "https://github.com/sponsors/ai"
-
}
-
],
-
"license": "MIT",
-
"dependencies": {
-
"baseline-browser-mapping": "^2.8.19",
-
"caniuse-lite": "^1.0.30001751",
-
"electron-to-chromium": "^1.5.238",
-
"node-releases": "^2.0.26",
-
"update-browserslist-db": "^1.1.4"
-
},
-
"bin": {
-
"browserslist": "cli.js"
-
},
-
"engines": {
-
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
-
}
-
},
"node_modules/camelcase": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-8.0.0.tgz",
···
"url": "https://github.com/sponsors/sindresorhus"
},
-
"node_modules/caniuse-lite": {
-
"version": "1.0.30001751",
-
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001751.tgz",
-
"integrity": "sha512-A0QJhug0Ly64Ii3eIqHu5X51ebln3k4yTUkY1j8drqpWHVreg/VLijN48cZ1bYPiqOQuqpkIKnzr/Ul8V+p6Cw==",
-
"funding": [
-
{
-
"type": "opencollective",
-
"url": "https://opencollective.com/browserslist"
-
},
-
{
-
"type": "tidelift",
-
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
-
},
-
{
-
"type": "github",
-
"url": "https://github.com/sponsors/ai"
-
}
-
],
-
"license": "CC-BY-4.0"
-
},
"node_modules/ccount": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz",
···
},
"node_modules/daisyui": {
-
"version": "5.3.9",
-
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.3.9.tgz",
-
"integrity": "sha512-741x1pGGSGHcrBYtdE7iKbqW1OoiijYdAZ8oJPZR9MhSKLcMBlHjKfN3YlM2/K7t5jd7O0sg4SqkVNPylalRFw==",
+
"version": "5.3.10",
+
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.3.10.tgz",
+
"integrity": "sha512-vmjyPmm0hvFhA95KB6uiGmWakziB2pBv6CUcs5Ka/3iMBMn9S+C3SZYx9G9l2JrgTZ1EFn61F/HrPcwaUm2kLQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/saadeghi/daisyui?sponsor=1"
···
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
-
"node_modules/electron-to-chromium": {
-
"version": "1.5.240",
-
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.240.tgz",
-
"integrity": "sha512-OBwbZjWgrCOH+g6uJsA2/7Twpas2OlepS9uvByJjR2datRDuKGYeD+nP8lBBks2qnB7bGJNHDUx7c/YLaT3QMQ==",
-
"license": "ISC"
-
},
"node_modules/emoji-regex": {
"version": "10.6.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.6.0.tgz",
···
"@esbuild/win32-arm64": "0.25.11",
"@esbuild/win32-ia32": "0.25.11",
"@esbuild/win32-x64": "0.25.11"
-
}
-
},
-
"node_modules/escalade": {
-
"version": "3.2.0",
-
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
-
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
-
"license": "MIT",
-
"engines": {
-
"node": ">=6"
},
"node_modules/escape-html": {
···
"unicode-trie": "^2.0.0"
},
-
"node_modules/fraction.js": {
-
"version": "4.3.7",
-
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz",
-
"integrity": "sha512-ZsDfxO51wGAXREY55a7la9LScWpwv9RxIrYABrlvOFBlH/ShPnrtsXeuUIfXKKOVicNxQ+o8JTbJvjS4M89yew==",
-
"license": "MIT",
-
"engines": {
-
"node": "*"
-
},
-
"funding": {
-
"type": "patreon",
-
"url": "https://github.com/sponsors/rawify"
-
}
-
},
"node_modules/fresh": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
···
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/parcel"
-
}
-
},
-
"node_modules/lilconfig": {
-
"version": "3.1.3",
-
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz",
-
"integrity": "sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==",
-
"license": "MIT",
-
"engines": {
-
"node": ">=14"
-
},
-
"funding": {
-
"url": "https://github.com/sponsors/antonk52"
},
"node_modules/longest-streak": {
···
"integrity": "sha512-jN8dK25fsfnMrVsEhluUTPkBFY+6ybu7jSB1n+ri/vOGjJxU8J9CZhpSGkHXSkFjtUhbmoncG/YG9ta5Ludqog==",
"license": "MIT"
},
-
"node_modules/node-releases": {
-
"version": "2.0.26",
-
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.26.tgz",
-
"integrity": "sha512-S2M9YimhSjBSvYnlr5/+umAnPHE++ODwt5e2Ij6FoX45HA/s4vHdkDx1eax2pAPeAOqu4s9b7ppahsyEFdVqQA==",
-
"license": "MIT"
-
},
"node_modules/normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
-
"license": "MIT",
-
"engines": {
-
"node": ">=0.10.0"
-
}
-
},
-
"node_modules/normalize-range": {
-
"version": "0.1.2",
-
"resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz",
-
"integrity": "sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
},
"node_modules/ofetch": {
-
"version": "1.4.1",
-
"resolved": "https://registry.npmjs.org/ofetch/-/ofetch-1.4.1.tgz",
-
"integrity": "sha512-QZj2DfGplQAr2oj9KzceK9Hwz6Whxazmn85yYeVuS3u9XTMOGMRx0kO95MQ+vLsj/S/NwBDMMLU5hpxvI6Tklw==",
+
"version": "1.5.0",
+
"resolved": "https://registry.npmjs.org/ofetch/-/ofetch-1.5.0.tgz",
+
"integrity": "sha512-A7llJ7eZyziA5xq9//3ZurA8OhFqtS99K5/V1sLBJ5j137CM/OAjlbA/TEJXBuOWwOfLqih+oH5U3ran4za1FQ==",
"license": "MIT",
"dependencies": {
-
"destr": "^2.0.3",
-
"node-fetch-native": "^1.6.4",
-
"ufo": "^1.5.4"
+
"destr": "^2.0.5",
+
"node-fetch-native": "^1.6.7",
+
"ufo": "^1.6.1"
},
"node_modules/ohash": {
···
"node": "^10 || ^12 || >=14"
},
-
"node_modules/postcss-load-config": {
-
"version": "4.0.2",
-
"resolved": "https://registry.npmjs.org/postcss-load-config/-/postcss-load-config-4.0.2.tgz",
-
"integrity": "sha512-bSVhyJGL00wMVoPUzAVAnbEoWyqRxkjv64tUl427SKnPrENtq6hJwUojroMz2VB+Q1edmi4IfrAPpami5VVgMQ==",
-
"funding": [
-
{
-
"type": "opencollective",
-
"url": "https://opencollective.com/postcss/"
-
},
-
{
-
"type": "github",
-
"url": "https://github.com/sponsors/ai"
-
}
-
],
-
"license": "MIT",
-
"dependencies": {
-
"lilconfig": "^3.0.0",
-
"yaml": "^2.3.4"
-
},
-
"engines": {
-
"node": ">= 14"
-
},
-
"peerDependencies": {
-
"postcss": ">=8.0.9",
-
"ts-node": ">=9.0.0"
-
},
-
"peerDependenciesMeta": {
-
"postcss": {
-
"optional": true
-
},
-
"ts-node": {
-
"optional": true
-
}
-
}
-
},
-
"node_modules/postcss-value-parser": {
-
"version": "4.2.0",
-
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
-
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
-
"license": "MIT"
-
},
"node_modules/prismjs": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.30.0.tgz",
···
},
"node_modules/shiki": {
-
"version": "3.13.0",
-
"resolved": "https://registry.npmjs.org/shiki/-/shiki-3.13.0.tgz",
-
"integrity": "sha512-aZW4l8Og16CokuCLf8CF8kq+KK2yOygapU5m3+hoGw0Mdosc6fPitjM+ujYarppj5ZIKGyPDPP1vqmQhr+5/0g==",
+
"version": "3.14.0",
+
"resolved": "https://registry.npmjs.org/shiki/-/shiki-3.14.0.tgz",
+
"integrity": "sha512-J0yvpLI7LSig3Z3acIuDLouV5UCKQqu8qOArwMx+/yPVC3WRMgrP67beaG8F+j4xfEWE0eVC4GeBCIXeOPra1g==",
"license": "MIT",
"dependencies": {
-
"@shikijs/core": "3.13.0",
-
"@shikijs/engine-javascript": "3.13.0",
-
"@shikijs/engine-oniguruma": "3.13.0",
-
"@shikijs/langs": "3.13.0",
-
"@shikijs/themes": "3.13.0",
-
"@shikijs/types": "3.13.0",
+
"@shikijs/core": "3.14.0",
+
"@shikijs/engine-javascript": "3.14.0",
+
"@shikijs/engine-oniguruma": "3.14.0",
+
"@shikijs/langs": "3.14.0",
+
"@shikijs/themes": "3.14.0",
+
"@shikijs/types": "3.14.0",
"@shikijs/vscode-textmate": "^10.0.2",
"@types/hast": "^3.0.4"
···
"url": "https://github.com/sponsors/sindresorhus"
},
+
"node_modules/typescript": {
+
"version": "5.9.3",
+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
+
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
+
"license": "Apache-2.0",
+
"peer": true,
+
"bin": {
+
"tsc": "bin/tsc",
+
"tsserver": "bin/tsserver"
+
},
+
"engines": {
+
"node": ">=14.17"
+
}
+
},
"node_modules/ufo": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.1.tgz",
···
},
-
"node_modules/update-browserslist-db": {
-
"version": "1.1.4",
-
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.4.tgz",
-
"integrity": "sha512-q0SPT4xyU84saUX+tomz1WLkxUbuaJnR1xWt17M7fJtEJigJeWUNGUqrauFXsHnqev9y9JTRGwk13tFBuKby4A==",
-
"funding": [
-
{
-
"type": "opencollective",
-
"url": "https://opencollective.com/browserslist"
-
},
-
{
-
"type": "tidelift",
-
"url": "https://tidelift.com/funding/github/npm/browserslist"
-
},
-
{
-
"type": "github",
-
"url": "https://github.com/sponsors/ai"
-
}
-
],
-
"license": "MIT",
-
"dependencies": {
-
"escalade": "^3.2.0",
-
"picocolors": "^1.1.1"
-
},
-
"bin": {
-
"update-browserslist-db": "cli.js"
-
},
-
"peerDependencies": {
-
"browserslist": ">= 4.21.0"
-
}
-
},
"node_modules/vfile": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz",
···
},
"node_modules/vite": {
-
"version": "6.4.1",
-
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
-
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
+
"version": "7.1.12",
+
"resolved": "https://registry.npmjs.org/vite/-/vite-7.1.12.tgz",
+
"integrity": "sha512-ZWyE8YXEXqJrrSLvYgrRP7p62OziLW7xI5HYGWFzOvupfAlrLvURSzv/FyGyy0eidogEM3ujU+kUG1zuHgb6Ug==",
"license": "MIT",
+
"peer": true,
"dependencies": {
"esbuild": "^0.25.0",
-
"fdir": "^6.4.4",
-
"picomatch": "^4.0.2",
-
"postcss": "^8.5.3",
-
"rollup": "^4.34.9",
-
"tinyglobby": "^0.2.13"
+
"fdir": "^6.5.0",
+
"picomatch": "^4.0.3",
+
"postcss": "^8.5.6",
+
"rollup": "^4.43.0",
+
"tinyglobby": "^0.2.15"
},
"bin": {
"vite": "bin/vite.js"
},
"engines": {
-
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
+
"node": "^20.19.0 || >=22.12.0"
},
"funding": {
"url": "https://github.com/vitejs/vite?sponsor=1"
···
"fsevents": "~2.3.3"
},
"peerDependencies": {
-
"@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
+
"@types/node": "^20.19.0 || >=22.12.0",
"jiti": ">=1.21.0",
-
"less": "*",
+
"less": "^4.0.0",
"lightningcss": "^1.21.0",
-
"sass": "*",
-
"sass-embedded": "*",
-
"stylus": "*",
-
"sugarss": "*",
+
"sass": "^1.70.0",
+
"sass-embedded": "^1.70.0",
+
"stylus": ">=0.54.8",
+
"sugarss": "^5.0.0",
"terser": "^5.16.0",
"tsx": "^4.8.1",
"yaml": "^2.4.2"
···
"resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.1.0.tgz",
"integrity": "sha512-147y/6YNh+tlp6nd/2pWq38i9h6mz/EuQ6njIrmW8D1BS5nCqs0P6DG+m6zTGnNz5I+uhZ0SHxBs9BsPrwcKDA==",
"license": "MIT"
-
},
-
"node_modules/yaml": {
-
"version": "2.8.1",
-
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.1.tgz",
-
"integrity": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==",
-
"license": "ISC",
-
"bin": {
-
"yaml": "bin.mjs"
-
},
-
"engines": {
-
"node": ">= 14.6"
-
}
},
"node_modules/yargs-parser": {
"version": "21.1.1",
-1
package.json
···
},
"dependencies": {
"@astrojs/node": "^9.5.0",
-
"@astrojs/tailwind": "^6.0.2",
"@atproto/api": "^0.17.4",
"@atproto/oauth-client-node": "^0.3.10",
"@tailwindcss/vite": "^4.1.16",
+4 -14
src/lib/context.ts
···
-
import { NodeOAuthClient } from '@atproto/oauth-client-node'
+
import type { AstroCookies } from 'astro'
import { createOAuthClient } from './oauth'
-
export type AppContext = {
-
oauthClient: NodeOAuthClient
-
}
-
-
let _ctx: AppContext | null = null
-
-
export async function getAppContext(): Promise<AppContext> {
-
if (_ctx) return _ctx
-
-
const oauthClient = await createOAuthClient()
-
-
_ctx = { oauthClient }
-
return _ctx
+
// Create a request-scoped OAuth client with cookie-based storage
+
export function getOAuthClient(cookies: AstroCookies) {
+
return createOAuthClient(cookies)
}
+5 -4
src/lib/oauth.ts
···
+
import type { AstroCookies } from 'astro'
import {
atprotoLoopbackClientMetadata,
NodeOAuthClient,
} from "@atproto/oauth-client-node";
import { env } from "./env";
-
import { SessionStore, StateStore } from "./storage";
+
import { CookieSessionStore, CookieStateStore } from "./storage";
-
export async function createOAuthClient() {
+
export function createOAuthClient(cookies: AstroCookies) {
const clientMetadata = atprotoLoopbackClientMetadata(
`http://localhost?${new URLSearchParams([
["redirect_uri", `http://127.0.0.1:${env.PORT}/api/oauth/callback`],
···
return new NodeOAuthClient({
clientMetadata,
-
stateStore: new StateStore(),
-
sessionStore: new SessionStore(),
+
stateStore: new CookieStateStore(cookies),
+
sessionStore: new CookieSessionStore(cookies),
});
}
+53 -12
src/lib/storage.ts
···
+
import type { AstroCookies } from 'astro'
import type {
NodeSavedSession,
NodeSavedSessionStore,
···
NodeSavedStateStore,
} from '@atproto/oauth-client-node'
-
// In-memory storage for OAuth state and sessions
-
// For production, you'd want to use a proper database or distributed cache
+
// Cookie-based storage for OAuth state and sessions
+
// All data is serialized into cookies for stateless operation
-
export class StateStore implements NodeSavedStateStore {
-
private store = new Map<string, NodeSavedState>()
+
export class CookieStateStore implements NodeSavedStateStore {
+
constructor(private cookies: AstroCookies) {}
async get(key: string): Promise<NodeSavedState | undefined> {
-
return this.store.get(key)
+
const cookieName = `oauth_state_${key}`
+
const cookie = this.cookies.get(cookieName)
+
if (!cookie?.value) return undefined
+
+
try {
+
const decoded = atob(cookie.value)
+
return JSON.parse(decoded) as NodeSavedState
+
} catch (err) {
+
console.warn('Failed to decode OAuth state:', err)
+
return undefined
+
}
}
async set(key: string, val: NodeSavedState) {
-
this.store.set(key, val)
+
const cookieName = `oauth_state_${key}`
+
const encoded = btoa(JSON.stringify(val))
+
+
this.cookies.set(cookieName, encoded, {
+
httpOnly: true,
+
secure: false,
+
sameSite: 'lax',
+
path: '/',
+
maxAge: 60 * 10, // 10 minutes (OAuth flow timeout)
+
})
}
async del(key: string) {
-
this.store.delete(key)
+
const cookieName = `oauth_state_${key}`
+
this.cookies.delete(cookieName, { path: '/' })
}
}
-
export class SessionStore implements NodeSavedSessionStore {
-
private store = new Map<string, NodeSavedSession>()
+
export class CookieSessionStore implements NodeSavedSessionStore {
+
constructor(private cookies: AstroCookies) {}
async get(key: string): Promise<NodeSavedSession | undefined> {
-
return this.store.get(key)
+
const cookieName = `oauth_session_${key}`
+
const cookie = this.cookies.get(cookieName)
+
if (!cookie?.value) return undefined
+
+
try {
+
const decoded = atob(cookie.value)
+
return JSON.parse(decoded) as NodeSavedSession
+
} catch (err) {
+
console.warn('Failed to decode OAuth session:', err)
+
return undefined
+
}
}
async set(key: string, val: NodeSavedSession) {
-
this.store.set(key, val)
+
const cookieName = `oauth_session_${key}`
+
const encoded = btoa(JSON.stringify(val))
+
+
this.cookies.set(cookieName, encoded, {
+
httpOnly: true,
+
secure: false,
+
sameSite: 'lax',
+
path: '/',
+
maxAge: 60 * 60 * 24 * 30, // 30 days
+
})
}
async del(key: string) {
-
this.store.delete(key)
+
const cookieName = `oauth_session_${key}`
+
this.cookies.delete(cookieName, { path: '/' })
}
}
+4 -4
src/pages/api/login.ts
···
import type { APIRoute } from 'astro'
-
import { getAppContext } from '../../lib/context'
+
import { getOAuthClient } from '../../lib/context'
-
export const POST: APIRoute = async ({ request, redirect }) => {
+
export const POST: APIRoute = async ({ request, cookies, redirect }) => {
try {
-
const ctx = await getAppContext()
+
const oauthClient = getOAuthClient(cookies)
const formData = await request.formData()
const handle = formData.get('handle')
···
return new Response('Invalid handle', { status: 400 })
}
-
const url = await ctx.oauthClient.authorize(handle, {
+
const url = await oauthClient.authorize(handle, {
scope: 'atproto transition:generic',
})
+3 -3
src/pages/api/logout.ts
···
import type { APIRoute } from 'astro'
-
import { getAppContext } from '../../lib/context'
+
import { getOAuthClient } from '../../lib/context'
import { getSession } from '../../lib/session'
export const POST: APIRoute = async (context) => {
try {
-
const ctx = await getAppContext()
+
const oauthClient = getOAuthClient(context.cookies)
const session = getSession(context.cookies)
if (session.did) {
try {
-
const oauthSession = await ctx.oauthClient.restore(session.did)
+
const oauthSession = await oauthClient.restore(session.did)
if (oauthSession) await oauthSession.signOut()
} catch (err) {
console.warn('Failed to revoke credentials:', err)
+4 -4
src/pages/api/oauth/callback.ts
···
import type { APIRoute } from 'astro'
-
import { getAppContext } from '../../../lib/context'
+
import { getOAuthClient } from '../../../lib/context'
import { getSession } from '../../../lib/session'
export const GET: APIRoute = async (context) => {
try {
-
const ctx = await getAppContext()
+
const oauthClient = getOAuthClient(context.cookies)
const url = new URL(context.request.url)
const params = new URLSearchParams(url.search)
···
if (session.did) {
try {
-
const oauthSession = await ctx.oauthClient.restore(session.did)
+
const oauthSession = await oauthClient.restore(session.did)
if (oauthSession) await oauthSession.signOut()
} catch (err) {
console.warn('OAuth restore failed during callback:', err)
}
}
-
const oauth = await ctx.oauthClient.callback(params)
+
const oauth = await oauthClient.callback(params)
session.did = oauth.session.did
await session.save()
+35 -28
src/pages/index.astro
···
---
-
import "../styles.css";
-
import { getSession } from "../lib/session";
-
import { getAppContext } from "../lib/context";
-
import { Agent } from "@atproto/api";
+
import '../styles.css'
+
import { getSession } from '../lib/session'
+
import { getOAuthClient } from '../lib/context'
+
import { Agent } from '@atproto/api'
-
const session = getSession(Astro.cookies);
-
const ctx = await getAppContext();
+
const session = getSession(Astro.cookies)
+
const oauthClient = getOAuthClient(Astro.cookies)
-
let agent: Agent | null = null;
-
let profile: any = null;
+
let agent: Agent | null = null
+
let profile: any = null
if (session.did) {
try {
-
const oauthSession = await ctx.oauthClient.restore(session.did);
+
const oauthSession = await oauthClient.restore(session.did)
if (oauthSession) {
-
agent = new Agent(oauthSession);
+
agent = new Agent(oauthSession)
try {
-
const profileResponse = await agent.com.atproto.repo.getRecord({
-
repo: agent.assertDid,
-
collection: "app.bsky.actor.profile",
-
rkey: "self",
-
});
-
profile = profileResponse.data;
+
const profileResponse = await agent.app.bsky.actor.getProfile({
+
actor: agent.assertDid,
+
})
+
profile = profileResponse.data
} catch (err) {
-
console.warn("Failed to fetch profile:", err);
+
console.warn('Failed to fetch profile:', err)
}
}
} catch (err) {
-
console.warn("OAuth restore failed:", err);
-
session.destroy();
+
console.warn('OAuth restore failed:', err)
+
session.destroy()
}
}
-
const displayName = profile?.value?.displayName || agent?.assertDid || "User";
-
const handle = agent?.assertDid || "";
+
const displayName = profile?.displayName || agent?.assertDid || 'User'
+
const handle = profile?.handle || agent?.assertDid || ''
+
const avatar = profile?.avatar
+
const description = profile?.description
---
<html lang="en" data-theme="dracula">
···
</head>
<body>
<div class="min-h-screen flex items-center justify-center">
-
<div class="card w-96 bg-base-100 shadow-xl">
+
<div class="card w-96 bg-base-200 shadow-xl p-8">
<div class="card-body">
{
agent ? (
<>
<h2 class="card-title justify-center mb-4">Welcome!</h2>
<div class="space-y-4">
-
<div class="text-center">
+
<div class="flex flex-col items-center text-center">
+
{avatar && (
+
<div class="avatar mb-4">
+
<div class="w-24 rounded-full">
+
<img src={avatar} alt={displayName} />
+
</div>
+
</div>
+
)}
<p class="text-lg font-semibold">{displayName}</p>
<p class="text-sm opacity-70">{handle}</p>
+
{description && (
+
<p class="text-sm mt-2 opacity-80">{description}</p>
+
)}
</div>
<form method="POST" action="/api/logout" class="w-full">
<button type="submit" class="btn btn-error w-full">
···
<input
type="text"
placeholder="Enter your handle (e.g. alice.bsky.social)"
-
class="input input-bordered join-item"
+
class="input input-bordered join-item w-full"
name="handle"
required
/>
-
<button
-
type="submit"
-
class="btn btn-primary btn-wide join-item"
-
>
+
<button type="submit" class="btn btn-primary join-item w-full">
Login
</button>
</div>
+2 -3
src/styles.css
···
-
@tailwind base;
-
@tailwind components;
-
@tailwind utilities;
+
@import "tailwindcss";
+
@plugin "daisyui" {
themes:
dracula --default,
-3
tailwind.config.mjs
···
/** @type {import('tailwindcss').Config} */
export default {
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
-
daisyui: {
-
themes: true,
-
},
};