-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from avantifellows/feature/data-fetching-using…
…-fetch Replacing axios with fetch for Nextjs Caching and Revalidation
- Loading branch information
Showing
9 changed files
with
221 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
"use server" | ||
"use server"; | ||
|
||
import axios from 'axios'; | ||
import getAxiosConfig from '../axiosConfig'; | ||
import { User } from '@/app/types'; | ||
import getFetchConfig from '../fetchConfig'; | ||
import { Student, User } from '@/app/types'; | ||
|
||
export const getUserName = async (studentId: string): Promise<User | null> => { | ||
const url = process.env.AF_DB_SERVICE_URL; | ||
const bearerToken = process.env.AF_DB_SERVICE_BEARER_TOKEN!; | ||
|
||
try { | ||
const response = await axios.get(`${url}/student`, { | ||
params: { student_id: studentId }, | ||
...getAxiosConfig(bearerToken), | ||
const queryParams = new URLSearchParams({ | ||
student_id: studentId, | ||
}); | ||
|
||
if (response.data.length === 0) { | ||
const urlWithParams = `${url}/student?${queryParams.toString()}`; | ||
const response = await fetch(urlWithParams, getFetchConfig(bearerToken)); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Error fetching student data: ${response.statusText}`); | ||
} | ||
|
||
const data: Student[] = await response.json(); | ||
|
||
if (data.length === 0) { | ||
console.warn(`No user found for student ID: ${studentId}`); | ||
return null; | ||
} | ||
|
||
return response.data[0].user; | ||
return data[0].user; | ||
} catch (error) { | ||
console.error('Error fetching student data:', error); | ||
throw error; | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.