public inbox for [email protected]
 help / color / mirror / Atom feed
From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v1 1/2] fix(http): only logout on 401 `Unauthorized` response
Date: Tue, 11 Mar 2025 21:11:28 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
---
 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<typing.ResponseAPI<typing.RenewTokenResponse>>;
     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


  reply	other threads:[~2025-03-11 14:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 14:11 [PATCH v1 0/2] Fix HTTP Muhammad Rizki
2025-03-11 14:11 ` Muhammad Rizki [this message]
2025-03-11 14:11 ` [PATCH v1 2/2] chore(profile): refetch user data on profile Muhammad Rizki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox