Open
Description
I've got cookie based auth but I cannot make it work on my NextJS Project in server components.
Working examples:
- Working example in server component
const getData2 = async () => {
try {
const response = await fetch(new URL(SAME_URL_AS_IN_LOGOUT_SERVICE), {
headers: { Cookie: cookies().toString() },
})
return response.json()
} catch(err){
console.log(err)
// console.log("error", err)
}
}
......
.....
Server component:
const data = await getData() // auth works here
- Working example in client component, looks like cookies are correctly passed here.
use client
React.useEffect(() => {
const getData = async () => {
const getDataNotWorkingAuth = async () => {
try {
return await LogoutService.isAuthorizedUsingGet();
} catch (err) {
console.log(err);
}
}
const data = await getDataNotWorkingAuth(); // Auth works here
}
getData();
}, []);
Not working example in server component:
OpenAPI.HEADERS = {
Cookie: cookies().toString()
}
const getDataNotWorkingAuth = async () => {
try {
return await LogoutService.isAuthorizedUsingGet()
} catch(err){
console.log(err)
// console.log("error", err)
}
}
...
...
Server component:
const data = getDataNotWorkingAuth() //not authenticated
Do you have any idea how to make it work with typescript codegen?
Metadata
Metadata
Assignees
Labels
No labels