From 01c8f092a078af23c5588107ef2a6858ed3b8d83 Mon Sep 17 00:00:00 2001
From: silverwind <me@silverwind.io>
Date: Sun, 16 Mar 2025 12:05:26 +0100
Subject: [PATCH] Simplify secure context check (#33906)

As discussed in
https://github.com/go-gitea/gitea/pull/33820/files#r1997532169.
---
 web_src/js/features/user-auth-webauthn.ts | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/web_src/js/features/user-auth-webauthn.ts b/web_src/js/features/user-auth-webauthn.ts
index e6c37581e0..1f336b9741 100644
--- a/web_src/js/features/user-auth-webauthn.ts
+++ b/web_src/js/features/user-auth-webauthn.ts
@@ -11,13 +11,10 @@ export async function initUserAuthWebAuthn() {
     return;
   }
 
-  if (window.location.protocol === 'http:') {
-    // webauthn is only supported on secure contexts
-    const isLocalhost = ['localhost', '127.0.0.1'].includes(window.location.hostname);
-    if (!isLocalhost) {
-      hideElem(elSignInPasskeyBtn);
-      return;
-    }
+  // webauthn is only supported on secure contexts
+  if (!window.isSecureContext) {
+    hideElem(elSignInPasskeyBtn);
+    return;
   }
 
   if (!detectWebAuthnSupport()) {