Fix OpenClaw: auto-include gateway token in dashboard link

This commit is contained in:
Gan, Jimmy
2026-02-22 18:30:34 +08:00
parent 8797231f53
commit 87fdabcd50
3 changed files with 26 additions and 2 deletions
+3
View File
@@ -34,3 +34,6 @@ WEBAUTHN_ORIGIN = os.environ.get("WEBAUTHN_ORIGIN", "https://nas.jimmygan.com")
# CORS # CORS
CORS_ORIGINS = os.environ.get("CORS_ORIGINS", "https://nas.jimmygan.com").split(",") CORS_ORIGINS = os.environ.get("CORS_ORIGINS", "https://nas.jimmygan.com").split(",")
# OpenClaw
OPENCLAW_GATEWAY_TOKEN = os.environ.get("OPENCLAW_GATEWAY_TOKEN", "")
+6 -1
View File
@@ -5,7 +5,7 @@ import platform
import time import time
import httpx import httpx
from fastapi import APIRouter, Query from fastapi import APIRouter, Query
from config import TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, VOLUME_ROOT from config import TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, VOLUME_ROOT, OPENCLAW_GATEWAY_TOKEN
router = APIRouter() router = APIRouter()
@@ -110,3 +110,8 @@ def _classify(method, path, status, user):
return "noise" return "noise"
# Info — everything else # Info — everything else
return "info" return "info"
@router.get("/openclaw-token")
def openclaw_token():
return {"token": OPENCLAW_GATEWAY_TOKEN}
+17 -1
View File
@@ -1,7 +1,23 @@
<script> <script>
import { onMount } from "svelte";
import { get } from "../lib/api.js";
let isTailscale = location.hostname.startsWith("100."); let isTailscale = location.hostname.startsWith("100.");
let isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1" || location.hostname.startsWith("192.168."); let isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1" || location.hostname.startsWith("192.168.");
let canAccess = isTailscale || isLocal; let canAccess = isTailscale || isLocal;
let token = $state("");
onMount(async () => {
if (canAccess) {
const res = await get("/system/openclaw-token");
token = res?.token || "";
}
});
function clawUrl() {
const base = `${location.protocol}//${location.hostname}:3100`;
return token ? `${base}/#token=${token}` : base;
}
</script> </script>
<div class="space-y-4"> <div class="space-y-4">
@@ -22,7 +38,7 @@
OpenClaw's security settings prevent it from being embedded inside the dashboard. Click below to launch the assistant securely in a new tab. OpenClaw's security settings prevent it from being embedded inside the dashboard. Click below to launch the assistant securely in a new tab.
</p> </p>
<a <a
href="{location.protocol}//{location.hostname}:3100" href={clawUrl()}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
class="inline-flex items-center justify-center px-6 py-3 border border-transparent text-base font-medium rounded-lg text-white bg-primary-600 hover:bg-primary-700 shadow-sm transition-colors" class="inline-flex items-center justify-center px-6 py-3 border border-transparent text-base font-medium rounded-lg text-white bg-primary-600 hover:bg-primary-700 shadow-sm transition-colors"