fix: remove dead code and add missing validation

- Consolidate PAIR_CODE_TTL_SECONDS to single source in utils
- Add min_length=1 validation on scopes field
- Remove unused pairExpiresIn ref, rawToken ref, dead emitter listener
- Fix formattedCode fallback to return normalized value
This commit is contained in:
nendo
2026-03-11 10:34:42 +09:00
parent ea5b7546aa
commit 6de2a478f3
4 changed files with 5 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
import json
from fastapi import HTTPException, Request, status
from pydantic import BaseModel
from pydantic import BaseModel, Field
from decorators.auth import protected_route
from endpoints.responses.client_token import (
@@ -16,6 +16,7 @@ from handler.database import db_client_token_handler
from handler.redis_handler import sync_cache
from models.client_token import ClientToken
from utils.client_tokens import (
PAIR_CODE_TTL_SECONDS,
build_admin_schema,
build_create_schema,
build_schema,
@@ -32,12 +33,11 @@ router = APIRouter(
)
MAX_TOKENS_PER_USER = 25
PAIR_CODE_TTL_SECONDS = 60
class ClientTokenCreatePayload(BaseModel):
name: str
scopes: list[str]
scopes: list[str] = Field(min_length=1)
expires_in: str | None = None

View File

@@ -57,10 +57,6 @@ function fetchTokens() {
onMounted(fetchTokens);
emitter?.on("showCreateClientTokenDialog", () => {
// Refetch after dialog closes via snackbar events
});
function onTokenCreated() {
fetchTokens();
}

View File

@@ -29,7 +29,6 @@ const rawToken = ref("");
const tokenId = ref<number | null>(null);
const pairCode = ref("");
const pairExpiresIn = ref(0);
const pairTimer = ref<ReturnType<typeof setInterval> | null>(null);
const pairCountdown = ref(0);
const pairStatus = ref<"pending" | "claimed" | "expired">("pending");
@@ -227,7 +226,6 @@ async function startPairing() {
try {
const { data } = await clientTokenApi.pairToken(tokenId.value);
pairCode.value = data.code;
pairExpiresIn.value = data.expires_in;
pairCountdown.value = data.expires_in;
pairLoading.value = false;
@@ -282,7 +280,6 @@ async function regeneratePairCode() {
try {
const { data } = await clientTokenApi.pairToken(tokenId.value!);
pairCode.value = data.code;
pairExpiresIn.value = data.expires_in;
pairCountdown.value = data.expires_in;
pairLoading.value = false;

View File

@@ -8,8 +8,7 @@ const route = useRoute();
const code = computed(() => (route.query.code as string) || "");
const callback = computed(() => (route.query.callback as string) || "");
const status = ref<"idle" | "exchanging" | "success" | "error">("idle");
const rawToken = ref("");
const status = ref<"idle" | "exchanging" | "error">("idle");
const errorMessage = ref("");
function isCustomScheme(url: string): boolean {
@@ -64,7 +63,7 @@ onMounted(async () => {
const formattedCode = computed(() => {
const c = code.value.replace("-", "").toUpperCase();
if (c.length === 8) return c.slice(0, 4) + "-" + c.slice(4);
return code.value;
return c;
});
</script>