Skip to content

Commit e3d7bd8

Browse files
committed
Only logged in users can access My Topics
1 parent 5b094df commit e3d7bd8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

app/controllers/my_topics_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class MyTopicsController < ApplicationController
2+
before_action :verify_user
23
def index
34
topics = Topic.includes(:user, :category, messages: :user)
45
.joins(:messages)
@@ -14,4 +15,10 @@ def index
1415

1516
render inertia: { topics: }
1617
end
18+
19+
private
20+
21+
def verify_user
22+
redirect_to topics_path unless current_user
23+
end
1724
end

app/frontend/components/Sidebar.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function getLinkClasses(currentUrl: string, targetUrl: string) {
1616
}
1717

1818
export default function Sidebar({ isOpen }: { isOpen: boolean }) {
19-
const { props: { categories }, url: currentUrl } = usePage()
19+
const { props: { categories, current_user: currentUser }, url: currentUrl } = usePage()
2020

2121
return (
2222
<aside
@@ -44,16 +44,18 @@ export default function Sidebar({ isOpen }: { isOpen: boolean }) {
4444
</svg>
4545
Topics
4646
</Link>
47-
<Link
47+
{currentUser && (
48+
<Link
4849
href="/my_topics"
4950
className={getLinkClasses(currentUrl, '/my_topics').link}
5051
>
5152
<svg className="mr-3 h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
5253
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
5354
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
5455
</svg>
55-
My Topics
56-
</Link>
56+
My Topics
57+
</Link>
58+
)}
5759
</div>
5860

5961
<div className="pt-6 border-t border-gray-200">

0 commit comments

Comments
 (0)