I wanna build a webside, using clerk as user managerment and openapi-typescript to build fetch client. but I encounter a problem that I cannot inject auth token through middleware of openapi-fetch, because useAuth() only can be used in Compenent, and Auth() method only can be used in Server side.
here is my code, which cannot work
const authenticationInjector: Middleware = {
async onRequest({request}) {
const {isSignedIn, userId, getToken} = useAuth();
if (userId) {
request.headers.set("Authorization", `Bearer ${await getToken({template: 'Server'})}`);
}
return request;
},
}
I don’t wanna inject auth token manually everytime in Compenent when I need to fetch data.
WWW-x is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.