Skip to content

Commit

Permalink
Locking some article pages behind login (#249)
Browse files Browse the repository at this point in the history
* Locked new upload page, article creation page, and article edit page behind login

* Locked article edit page behind login
  • Loading branch information
ansengarvin authored Apr 26, 2024
1 parent 401a150 commit a15ae9e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/routes/Article.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
let article: Article;
let notFound = false;
onMount(async () => {
if (editMode && !$user.loggedIn) {
alert(
"You are not logged in. You are being redirected to home. TODO: Make this better."
);
navigate("/");
}
await refreshArticle();
});
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/routes/EditArticle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { navigate } from "svelte-routing";
import { Backend, setToken, type Article } from "../lib/backend";
import { onMount } from "svelte";
import { user } from "../lib/stores/user";
export let articleTitle: string;
let title: string = "";
Expand All @@ -13,6 +14,13 @@
let error = false;
let article: Article;
onMount(async () => {
if (!$user.loggedIn) {
alert(
"You are not logged in. You are being redirected to home. TODO: Make this better."
);
navigate("/");
}
try {
article = await Backend.getArticle(articleTitle);
} catch (e) {
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/routes/Upload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
UploadSolid,
} from "flowbite-svelte-icons";
import { navigate } from "svelte-routing";
import { onMount } from "svelte";
import { user } from "../lib/stores/user";
onMount(async () => {
if (!$user.loggedIn) {
alert(
"You are not logged in. You are being redirected to home. TODO: Make this better."
);
navigate("/");
}
})
</script>

<section class="p-5">
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/routes/UploadArticle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
import { Label, Input, Button, Helper } from "flowbite-svelte";
import { navigate } from "svelte-routing";
import { Backend, setToken } from "../lib/backend";
import { onMount } from "svelte";
import { user } from "../lib/stores/user";
let title: string = "";
let description: string = "";
let error = false;
onMount(async () => {
if (!$user.loggedIn) {
alert(
"You are not logged in. You are being redirected to home. TODO: Make this better."
);
navigate("/");
}
})
</script>

<section class="p-5">
Expand Down

0 comments on commit a15ae9e

Please sign in to comment.