fix(setup): pre-fill public base URL and require it in the wizard

An empty firebreak_public_base_url only works while the person filling in
the wizard happens to be browsing the same origin Forgejo redirects back
to, so it can look fine during local setup and still be wrong in
production. It also leaves share URLs relative, since there is no
externally resolvable origin to build them from.

The setup page already derived the request's base URL to display the OAuth
callback hint, but persisted "" instead, so the field and the hint could
disagree. Pass the derived value through as the field's value and mark the
input required, dropping the hint that told users to leave it blank on
localhost.
This commit is contained in:
ZTatman 2026-10-05 15:58:47 -04:00
parent 82d50bff59
commit e64315f68d
2 changed files with 9 additions and 6 deletions

View file

@ -61,9 +61,11 @@ async def setup_page(
"reconfiguring": existing is not None and has_users,
"forgejo_base_url": existing.forgejo_base_url if existing else "",
"forgejo_oauth_client_id": existing.forgejo_oauth_client_id if existing else "",
"firebreak_public_base_url": existing.firebreak_public_base_url
if existing
else "",
# Pre-fill with the request's own base URL so the field is never
# accidentally left blank: an empty value only works while the caller
# is browsing the same origin that Forgejo redirects back to, and any
# generated share link needs an externally resolvable address.
"firebreak_public_base_url": public_base,
"oauth_callback_url": f"{public_base}/auth/callback/forgejo",
}
return templates.TemplateResponse(request, "setup.html", ctx)

View file

@ -112,16 +112,17 @@
<label for="firebreak_public_base_url"
class="block text-xs font-semibold uppercase tracking-[0.05em] text-[#f7f2e8]/50 mb-1.5">
Public Base URL
<span class="ml-1 normal-case tracking-normal font-normal text-[#f7f2e8]/30">(optional)</span>
</label>
<input type="url"
id="firebreak_public_base_url"
name="firebreak_public_base_url"
class="block w-full rounded-md border border-[#f7f2e8]/14 bg-[#1f2226] px-3 py-2.5 text-sm text-[#f7f2e8] placeholder:text-[#f7f2e8]/30 focus:border-[#f7f2e8]/30 focus:outline-none focus:ring-2 focus:ring-[#f7f2e8]/10"
placeholder="https://share.example.com"
required
value="{{ firebreak_public_base_url }}" />
<p class="mt-1.5 text-xs text-[#f7f2e8]/30">
Your production domain for OAuth redirects. Leave blank on localhost &mdash; Firebreak will use <code class="font-mono text-[#f7f2e8]/40">http://localhost:8000</code> automatically.
The address Forgejo redirects back to after sign-in, and the origin
share links point at. Pre-filled from how you reached this page
&mdash; change it to your real domain once Firebreak is deployed.
</p>
</div>
<button type="submit" class="btn btn-primary w-full mt-2">