Skip to content

Commit 9e4a121

Browse files
use unauthorized page for users
1 parent 8e13c9e commit 9e4a121

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

astro-authproto/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bluesky and beyond.
2525
- [ ] Fix the state bits in the oauth login route
2626
- [x] Figure out what's up with weird amount of implementations in lib/
2727
- [ ] Clean up client-metadata duplication
28+
- [ ] Rename genericData to writeData
2829

2930
// Tip!
3031
Want to see what gets saved by the storage? Use

astro-authproto/__example__/src/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
1717
}
1818

1919
const agent = new AtpBaseClient("https://public.api.bsky.app");
20-
const relationships = await agent.app.bsky.graph.getRelationships({ actor: HAETAE_DID, others: [loggedInDid] });
20+
const relationships = await agent.app.bsky.graph.getRelationships({ actor: FUJOCODED_DID, others: [loggedInDid] });
2121
const usersRelationship = relationships.data.relationships.at(0);
2222

2323
// True if the current user follows you
@@ -28,7 +28,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
2828
const mutuals = follower && following;
2929

3030
if (!following) {
31-
return context.redirect("/?reason=unauthorized");
31+
return context.rewrite(new URL("/unauthorized", context.url));
3232
}
3333

3434
return next();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import { Login } from "@fujocoded/authproto/components";
3+
34
const user = Astro.locals.loggedInUser;
45
const redirectReason = Astro.url.searchParams.get("reason");
56
---
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
const loggedInUser = Astro.locals.loggedInUser;
3+
---
4+
5+
<html lang="en">
6+
<head>
7+
<meta charset="utf-8" />
8+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
9+
<meta name="viewport" content="width=device-width" />
10+
<meta name="generator" content={Astro.generator} />
11+
<title>Astro</title>
12+
</head>
13+
<body>
14+
<h1>STRANGER, BEGONE!</h1>
15+
Only friends are allowed on <code>{Astro.originPathname}</code>. <br/>
16+
{loggedInUser && <>You {loggedInUser.handle}, are NOT a friend.</>}
17+
{!loggedInUser && <>I have no idea who you are.</>}
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)