Skip to content

Refactor authentication logic in fetch.ts #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iKausik
Copy link

@iKausik iKausik commented May 19, 2025

What kind of change does this PR introduce?

  • 🛠 Refactor (Code improvement without changing functionality)

What is the current behavior?

  • fetch.ts currently sets accessToken using a nullish coalescing (??) fallback.

  • This can lead to unintended behavior where supabaseKey is assigned if getAccessToken() returns undefined or null.

Before (Current behavior):

const accessToken = (await getAccessToken()) ?? supabaseKey;

if (!headers.has('Authorization')) {
      headers.set('Authorization', `Bearer ${accessToken}`)
    }

What is the new behavior?

  • The refactored code separates token retrieval from fallback logic.

  • Now, authentication headers are set only if accessToken exists.

  • This improves clarity and avoids accidental assignment of Authorization: Bearer undefined.

After (Refactored behavior):

const accessToken = await getAccessToken()

if (accessToken && !headers.has('Authorization')) {
      headers.set('Authorization', `Bearer ${accessToken}`)
    }

Additional context

  • This change improves readability without altering core functionality.

  • No breaking changes expected.

  • Code remains compatible with the existing authentication flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant