From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1741702306; bh=xMKrT7LOxb8ftPO8QiKysly3WxN6J+WPU4FliygKZzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=GzPGLPpLiRjXBmvfZEliu0RKvq5qj7ep5FdzgHZ7ngw+a589waWlGtqacgXfnldDI wqag0gQChUjo5GUlN55vWiUNbO/BlfB+7Z4HiupW1wrgD4plF5zUSMLYbR8cV/X7nV u6+NXcK36V5C+gpAtNSnX6FjguH5P5WKyp/ap2KqSwIck5rr5it3oo9487dI5DaelK BV1ljeQ7k5l7dlvmDULTfp+3Q7jVApAg2GJ+mpfXAeLqxZ5boJGX8VWnzmZNe6eGO+ Pzxj7zhFhj8SpLFgA6NXJ5yyCMFBTUaO8y5stlWP1JHj2vET0GVJzMdPGUAwnAyeEU B/fRdDPr0uCpw== Received: from kanazawa.. (unknown [36.84.53.160]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id BC6D020B49A0; Tue, 11 Mar 2025 14:11:45 +0000 (UTC) From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 1/2] fix(http): only logout on 401 `Unauthorized` response Date: Tue, 11 Mar 2025 21:11:28 +0700 Message-ID: <20250311141130.15924-2-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250311141130.15924-1-kiizuha@gnuweeb.org> References: <20250311141130.15924-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Previously, users were always redirected to the login page if the status code was not `200`. This commit fixes that issue by only logging out when the status code is `401` and the response indicates `Unauthorized`, meaning the token is either invalid or expired. Signed-off-by: Muhammad Rizki --- src/lib/hooks/http.svelte.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/hooks/http.svelte.ts b/src/lib/hooks/http.svelte.ts index f30687d..6a67209 100644 --- a/src/lib/hooks/http.svelte.ts +++ b/src/lib/hooks/http.svelte.ts @@ -54,7 +54,7 @@ client.interceptors.response.use( const response = err.response as AxiosResponse>; const status = response ? response.status : null; - if (status !== 200) { + if (status === 401 && response.data.res?.msg === "Unauthorized") { localStorage.removeItem("gwm_token"); localStorage.removeItem("gwm_token_exp_at"); localStorage.removeItem("gwm_uinfo"); -- Muhammad Rizki