-
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.
feat(future) server fetch for; (Error: Server Functions cannot be cal…
…led during initial render. This would create a fetch waterfall. Try to use a Server Component to pass data to Client Components instead.
- Loading branch information
1 parent
8bf382b
commit 42befb9
Showing
4 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use server'; | ||
|
||
import { DataResponse } from '@/page'; | ||
import ApiServerClient from '@/providers/axios-server'; | ||
|
||
export async function fetchData() { | ||
const res = (await ApiServerClient) | ||
.get<DataResponse>('/v1/products') | ||
.then((response) => { | ||
return response.data.data; | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axios from 'axios'; | ||
|
||
import { getSession } from 'next-auth/react'; | ||
|
||
import { auth } from '@/api/auth/[...nextauth]/auth'; | ||
|
||
const baseURL = process.env.NEXT_PUBLIC_BACKEND_API_URL || 'http://127.0.0.1:8000'; | ||
|
||
const ApiServerClient = async () => { | ||
const defaultOptions = { | ||
baseURL: baseURL + `/api`, | ||
}; | ||
|
||
const test = await auth(); | ||
console.log('test', test); | ||
|
||
const instance = axios.create(defaultOptions); | ||
|
||
// instance.interceptors.request.use(async (request) => { | ||
// const session = await getSession(); | ||
// if (session) { | ||
// request.headers.Authorization = `Bearer ${session?.user.access_token}`; | ||
// request.headers.Accept = 'application/json'; | ||
// } | ||
// return request; | ||
// }); | ||
|
||
instance.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
console.log('error', error); | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
return instance; | ||
}; | ||
|
||
export default ApiServerClient(); |