Project-Chirp / chirp-frontend

Frontend of Chirp
2 stars 3 forks source link

T67 Custom Axios Hook #128

Open NasihNazeem opened 1 month ago

NasihNazeem commented 1 month ago

Related Issues

Closes #67

Linked Issue: #127

Summary

This pull request introduces a custom useAxios hook to streamline API requests in our application. The hook integrates Auth0 for authentication and provides a unified interface for making authenticated HTTP requests.

Key features:

This aims to simplify API calls, reduce the amount of boilerplate code and ensure consistent authentication and error handling.

Changes Made

  1. Created a new custom hook useAxios:
    • Implemented useCallback for memoized function calls (sendRequest)
    • Uses Auth0's getAccessTokenSilently for JWT verification
    • Uses axios for HTTP requests
    • Supports custom headers, request body and URL parameters
  2. Implemented environment variable check for base url:
    • Created an env variable for the base_url including /api
    • Throws an error if the base url is not defined

Future Improvements:

Screenshots

No additional screenshots

Testing Instructions

No additional testing instructions

Special Notes for Your Reviewer(s)