From f8d08138d19ccf81247cabe846d0660ba43a5add Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Mon, 29 May 2023 13:59:15 +0800 Subject: [PATCH] fix: jwt_token blank (#30) --- frontend/src/App.vue | 2 +- frontend/src/views/Index.vue | 2 +- router/user.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index a50f013..1c3be41 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -20,7 +20,7 @@ const fetchSettings = async () => { const response = await fetch(`${API_BASE}/api/v1/settings`, { method: "GET", headers: { - Authorization: `Bearer ${state_jwt.value || "xxx"}`, + "Authorization": `Bearer ${state_jwt.value || "xxx"}`, "Content-Type": "application/json" }, }); diff --git a/frontend/src/views/Index.vue b/frontend/src/views/Index.vue index fde2f1b..4bfcfbe 100644 --- a/frontend/src/views/Index.vue +++ b/frontend/src/views/Index.vue @@ -43,7 +43,7 @@ const onSubmit = async () => { plum_flower: prompt_type.value == "plum_flower" ? plum_flower.value : null, }), headers: { - Authorization: `Bearer ${state_jwt.value || "xxx"}`, + "Authorization": `Bearer ${state_jwt.value || "xxx"}`, "Content-Type": "application/json" }, }); diff --git a/router/user.py b/router/user.py index 4a07917..209e223 100644 --- a/router/user.py +++ b/router/user.py @@ -20,8 +20,8 @@ def get_user( ) -> Optional[User]: try: jwt_token = credentials.credentials - if jwt_token == DEFAULT_TOKEN: - return "" + if not jwt_token or jwt_token == DEFAULT_TOKEN: + return payload = jwt.decode( jwt_token, settings.jwt_secret, algorithms=["HS256"]) jwt_payload = User.parse_obj(payload)