Skip to content

Commit 855ba16

Browse files
create page for followers only
1 parent ed74800 commit 855ba16

File tree

5 files changed

+137
-2
lines changed

5 files changed

+137
-2
lines changed

astro-authproto/__example__/package-lock.json

Lines changed: 101 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

astro-authproto/__example__/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@astrojs/db": "^0.17.2",
1414
"@astrojs/node": "^9.4.0",
15+
"@atproto/api": "^0.17.2",
1516
"@fujocoded/authproto": "file:..",
1617
"astro": "^5.12.9"
1718
}

astro-authproto/__example__/src/pages/index.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import { Login } from "@fujocoded/authproto/components";
33
const user = Astro.locals.loggedInUser;
4+
const redirectReason = Astro.url.searchParams.get("reason");
45
---
56

67
<html lang="en">
@@ -14,5 +15,7 @@ const user = Astro.locals.loggedInUser;
1415
<body>
1516
{!user ? "Please log in:" : `Welcome ${user.handle} (${user.did})`}
1617
<Login />
18+
19+
{redirectReason == "unauthorized" && <div>Sorry, you can't play with us</div>}
1720
</body>
1821
</html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
import Login from "../../../dist/components/Login.astro";
3+
import {AtpBaseClient} from "@atproto/api";
4+
5+
const SITE_OWNER_DID = "did:plc:dg2qmmjic7mmecrbvpuhtvh6";
6+
const user = Astro.locals.loggedInUser;
7+
if (!user?.did) {
8+
return Astro.redirect("/?reason=unauthorized");
9+
}
10+
const agent = new AtpBaseClient("https://public.api.bsky.app");
11+
const following = await agent.app.bsky.graph.getFollows({actor: SITE_OWNER_DID});
12+
const isFollowed = following.data.follows.some(follow => follow.did === user.did);
13+
14+
if (!isFollowed) {
15+
return Astro.redirect("/?reason=unauthorized");
16+
}
17+
---
18+
19+
<html lang="en">
20+
<head>
21+
<meta charset="utf-8" />
22+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
23+
<meta name="viewport" content="width=device-width" />
24+
<meta name="generator" content={Astro.generator} />
25+
<title>Astro</title>
26+
</head>
27+
<body>
28+
Only friends allowed. You {user.handle}, are a friend.
29+
<Login />
30+
</body>
31+
</html>

astro-authproto/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"scripts": {
2828
"build": "tsdown",
29-
"dev": "tsdown --watch",
29+
"dev": "tsdown --watch --ignore-watch __example__",
3030
"validate": "npx publint",
3131
"test": "vitest"
3232
},

0 commit comments

Comments
 (0)