Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/invidious.cr
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ end

before_all do |env|
Invidious::Routes::BeforeAll.handle(env)

# Redirect unauthenticated users if require_login is enabled
if CONFIG.require_login && env.get?("user").nil?
path = env.request.path
allowed = {
"/login", "/register", "/api/",
"/sb/", "/vi/", "/s_p/", "/yts/", "/ggpht/",
"/api/manifest/", "/videoplayback", "/latest_version",
"/download", "/companion/",
}

is_allowed = allowed.any? { |p| path.starts_with?(p) }
is_allowed ||= path.starts_with?("/embed/") && !CONFIG.require_login_for_embeds

unless is_allowed
env.redirect "/login?referer=#{URI.encode_www_form(path)}"
halt env, 302
end
end
end

Invidious::Routing.register_all
Expand Down
2 changes: 2 additions & 0 deletions src/invidious/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Config
property popular_enabled : Bool = true
property captcha_enabled : Bool = true
property login_enabled : Bool = true
property require_login : Bool = false
property require_login_for_embeds : Bool = false
property registration_enabled : Bool = true
property statistics_enabled : Bool = false
property admins : Array(String) = [] of String
Expand Down
Loading