Skip to content

Commit 4ada796

Browse files
authored
feat: integrate authentication on word editor page (#11)
This Pull Request integrates authentication on the word editor page at `/editor`; this means a user is required to login via github oauth flow in order to access this page. When a user tries to access this page and they are not authenticated, they get redirected to the `/login` page where they're requested to authorize via github oauth flow and back to the `editor` after they complete authorization. ### Changes Made - Integrated the `doAuth` action in the word editor page on the server side. ```js // src/pages/editor/index.astro const { url: { pathname }, redirect } = Astro; const { isAuthed, authedData: userData } = await doAuth(Astro); if (!isAuthed) return redirect(`/login?redirect=${pathname}`); $userData.set(userData); ``` - Fixed a tiny change in the `word-editor` for accessibility ### Screencast/Screenshot [screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.03.30-19_18_45.webm](https://github.com/babblebey/jargons.dev/assets/25631971/b8775272-f343-4cde-857e-1a36635768ac) 📖
1 parent dc2bb1a commit 4ada796

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/components/islands/word-editor.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ function Preview({ className, ...props }) {
5757

5858
<div className="max-w-4xl space-y-8 mx-auto">
5959
<div className="w-full">
60-
<h1 className="text-4xl font-black">
61-
{ title }
62-
</h1>
60+
{title && (
61+
<h1 className="text-4xl font-black">
62+
{ title }
63+
</h1>
64+
)}
6365
</div>
6466

6567
<article className="w-full max-w-screen-lg prose">

src/pages/editor/index.astro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
---
2+
import doAuth from "../../lib/actions/do-auth";
3+
import { $userData } from "../../stores/user.js";
24
import BaseLayout from "../../layouts/base.astro";
35
import Navbar from "../../components/navbar.astro";
46
import WordEditor from "../../components/islands/word-editor.jsx";
7+
8+
const { url: { pathname }, redirect } = Astro;
9+
const { isAuthed, authedData: userData } = await doAuth(Astro);
10+
if (!isAuthed) return redirect(`/login?redirect=${pathname}`);
11+
// @ts-expect-error
12+
$userData.set(userData);
513
---
614

715
<BaseLayout

0 commit comments

Comments
 (0)