Skip to content

Commit afa38c9

Browse files
use relationship endpoint for secret page
1 parent 855ba16 commit afa38c9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22
import Login from "../../../dist/components/Login.astro";
33
import {AtpBaseClient} from "@atproto/api";
44
5-
const SITE_OWNER_DID = "did:plc:dg2qmmjic7mmecrbvpuhtvh6";
5+
const MS_BOBA_DID = "did:plc:r2vpg2iszskbkegoldmqa322";
6+
const HAETAE_DID = "did:plc:dg2qmmjic7mmecrbvpuhtvh6";
7+
const FUJOCODED_DID = "did:plc:737bslnnf7vyaktosjlrshmd";
68
const user = Astro.locals.loggedInUser;
79
if (!user?.did) {
810
return Astro.redirect("/?reason=unauthorized");
911
}
1012
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+
const relationships = await agent.app.bsky.graph.getRelationships({actor: FUJOCODED_DID, others: [user.did]});
14+
const usersRelationship = relationships.data.relationships.at(0);
1315
14-
if (!isFollowed) {
16+
// True if the current user follows you
17+
const follower = usersRelationship && "followedBy" in usersRelationship && Boolean(usersRelationship.followedBy);
18+
// True if you follow the current user
19+
const following = usersRelationship && "following" in usersRelationship && Boolean(usersRelationship.following);
20+
// True if this is a mutual relationship
21+
const mutuals = follower && following;
22+
23+
if (!following) {
1524
return Astro.redirect("/?reason=unauthorized");
1625
}
1726
---

0 commit comments

Comments
 (0)