Open mstosio opened 2 months ago
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
2. Working example in client component, looks like cookies are correctly passed here. ```javascript 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?
@mstosio If you're interested in resolving this, you'll have to migrate to https://github.com/hey-api/openapi-ts and then we can have a look
@mrlubos I'll try to do it ;)
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
} ...... ..... Server component: const data = await getData() // auth works here
Not working example in server component:
Do you have any idea how to make it work with typescript codegen?