Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS Server Comoponents #2133

Open
mstosio opened this issue May 6, 2024 · 2 comments
Open

NextJS Server Comoponents #2133

mstosio opened this issue May 6, 2024 · 2 comments
Assignees

Comments

@mstosio
Copy link
Contributor

mstosio commented May 6, 2024

I've got cookie based auth but I cannot make it work on my NextJS Project in server components.

Working examples:

  1. 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
  1. 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?

@mrlubos
Copy link
Collaborator

mrlubos commented May 6, 2024

@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

@mstosio
Copy link
Contributor Author

mstosio commented May 6, 2024

@mrlubos I'll try to do it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants