Skip to content

Commit

Permalink
Merge pull request #77 from ruchernchong/76-add-authorisation-while-f…
Browse files Browse the repository at this point in the history
…etching-api

Add authorisation while fetching API
  • Loading branch information
ruchernchong authored Aug 6, 2024
2 parents 1448cb3 + 7408224 commit c675fef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ NEXT_PUBLIC_GA_MEASUREMENT_ID=
NEXT_PUBLIC_FEATURE_FLAG_RELEASED=
NEXT_PUBLIC_REVALIDATE_TOKEN=
CLOUDFLARE_API_TOKEN=
SG_CARS_TRENDS_API_TOKEN=
1 change: 1 addition & 0 deletions .github/workflows/sst.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
NEXT_PUBLIC_SITE_URL: ${{ vars.NEXT_PUBLIC_SITE_URL }}
NEXT_PUBLIC_REVALIDATE_TOKEN: ${{ secrets.NEXT_PUBLIC_REVALIDATE_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sst.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
NEXT_PUBLIC_SITE_URL: ${{ vars.NEXT_PUBLIC_SITE_URL }}
NEXT_PUBLIC_REVALIDATE_TOKEN: ${{ secrets.NEXT_PUBLIC_REVALIDATE_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
Expand Down
6 changes: 6 additions & 0 deletions utils/fetchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ export const fetchApi = async <T>(
url: string,
options: RequestInit = {},
): Promise<T> => {
options = {
...options,
headers: {
Authorization: `Bearer ${process.env.SG_CARS_TRENDS_API_TOKEN}`,
},
};
const response = await fetch(url, options);

if (!response.ok) {
Expand Down

0 comments on commit c675fef

Please sign in to comment.