Skip to content

apiClient keeps a stale bearer token after logout, sending it on subsequent requests #637

Description

@K1NGD4VID

Category: Functional Edge Case

Repository location: apps/web/lib/api.ts (ApiClient.setToken, initApiClientWithToken), apps/web/hooks/useAuth.ts (logout)

Problem
initApiClientWithToken() only calls apiClient.setToken(token) when token is truthy: if (token) { apiClient.setToken(token); }. useAuth.ts's logout() sets the store token to null then calls initApiClientWithToken(), expecting the client to clear its token — but since the token is falsy, the call is a no-op and the previous JWT stays cached inside apiClient indefinitely.

Evidence

function initApiClientWithToken(): void {
  const token = useWalletStore.getState().token;
  if (token) {
    apiClient.setToken(token);
  }
}
// useAuth.ts logout():
setToken(null);
initApiClientWithToken(); // token is null -> apiClient.token stays stale
disconnect();

Suggested implementation
Add an explicit clearToken() method to ApiClient and call it whenever the token is falsy: token ? apiClient.setToken(token) : apiClient.clearToken().

Acceptance criteria

  • After calling logout(), any subsequent request through apiClient.fetch sends no Authorization header.
  • A unit test asserts apiClient's internal token is null after initApiClientWithToken() runs with a null store token.

Difficulty: Easy

Expected impact: Closes a real auth-hygiene gap where a logged-out session keeps authenticating API calls with a stale JWT.


Filed as part of the second repository-wide audit (deeper refinements following the first cleanup pass).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingfrontendNext.js Web Application

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions