Skip to content
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

fix: Improve authentication handling in fetchWithAuth. #1373

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

Conversation

anuragchvn-blip
Copy link

🚀 What This PR Does

  • Improves fetchWithAuth by adding better error handling for getAccessToken().
  • Logs meaningful errors when retrieving an access token fails.
  • Ensures API calls in Supabase SDK always have proper authentication headers.

🔧 Why This Is Important

  • Prevents silent failures in authentication.
  • Improves debugging experience for developers using Supabase SDK.

✅ How to Test

  1. Run Supabase SDK in a Node.js and browser environment.
  2. Intentionally break getAccessToken() to verify error logging.

Would love feedback from maintainers! 🚀

const accessToken = (await getAccessToken()) ?? supabaseKey
let accessToken: string | null
try {
accessToken = (await getAccessToken()) ?? supabaseKey

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great to see the error handling here! Just a thought: the catch block will only execute if getAccessToken() throws an error. If getAccessToken() returns null (and doesn't throw an error), the catch block won't be reached. We might want to add a check to ensure accessToken has a valid value after the try block, or clarify the expected behavior of getAccessToken() to ensure it always either returns a token or throws an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, @m1nsuppp! You're absolutely right—if getAccessToken() returns null without throwing an error, the catch block won't be triggered. I’ll update the implementation to explicitly check whether accessToken is valid after the try block. We could either throw an error manually if it's null or ensure getAccessToken() always throws when it fails.

Would love your thoughts on the best approach here!

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.

2 participants