Need to create Interceptor for server component
Unanswered
Polar bear posted this in #help-forum
Polar bearOP
Hello everyone,
I need some help with managing authentication tokens in server-side API calls. Here's the situation:
I'm calling an API from a server component, and I need to pass an auth token in the header, specifically a Bearer Token. To avoid manually adding this token to every API call, I was considering creating an interceptor.
I've read several blogs about implementing interceptors, but they all seem to focus on using axios, which, to my knowledge, is typically used on the client side.
My questions are:
How can I create an interceptor for API calls on the server side?
Is there a way to manage this without using axios, or is there a way to use axios effectively in a server-side environment?
Any examples or guidance would be greatly appreciated. Thank you!
I need some help with managing authentication tokens in server-side API calls. Here's the situation:
I'm calling an API from a server component, and I need to pass an auth token in the header, specifically a Bearer Token. To avoid manually adding this token to every API call, I was considering creating an interceptor.
I've read several blogs about implementing interceptors, but they all seem to focus on using axios, which, to my knowledge, is typically used on the client side.
My questions are:
How can I create an interceptor for API calls on the server side?
Is there a way to manage this without using axios, or is there a way to use axios effectively in a server-side environment?
Any examples or guidance would be greatly appreciated. Thank you!
4 Replies
@joulev https://github.com/sindresorhus/ky
Polar bearOP
Will this work in Server component?
Yes
Polar bearOP
OKay thanks. Will definitely gonna try this