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

Handle cookies options #113

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Conversation

BearToCode
Copy link
Contributor

@BearToCode BearToCode commented Feb 22, 2024

The previous proxy that was used to edit SvelteKit cookies did not take in account the cookies options.

This still does not have the exact same behaviour as the SvelteKit implementation, but should be the same for most cases. Using the default implementation would require access to the internal API.

I also fixed a bug where old cookies were set again for every request.
Cookies now also have Path: / by default, instead of Path: /trpc.

Copy link

codesandbox bot commented Feb 22, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@icflorescu icflorescu merged commit c00469c into icflorescu:main Feb 28, 2024
@shirecoding
Copy link

shirecoding commented Mar 4, 2024

yea i have this same issue when i tried setting 2 cookies


                    ctx.cookies.set("token", token, {
                        path: "/",
                        httpOnly: true,
                        secure: true,
                        sameSite: "strict",
                        maxAge: parseInt(PUBLIC_JWT_EXPIRES_IN), // in seconds
                    });
                    ctx.cookies.set("refreshToken", refreshToken, {
                        path: "/",
                        httpOnly: true,
                        secure: true,
                        sameSite: "strict",
                        maxAge: parseInt(PUBLIC_REFRESH_JWT_EXPIRES_IN), // in seconds
                    });

                    return { status: "success", token };

I migrated from sveltekit endpoint to trpc and this was working on sveltekit

but on trpc all the options were missing, also it seems its only able to set 1 cookie and not multiple

this this fix it?

@BearToCode
Copy link
Contributor Author

Yes, it should be working now. Try updating and see how it goes

@shirecoding
Copy link

shirecoding commented Mar 4, 2024

I just tried the new version, the options seem to be passing, but it still only supports 1 cookie :(

it looks like the set-cookie is combined into 1 header

Set-Cookie:
token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwdWJsaWNLZXkiOiJhN1BReU1OWXhpa1VUNWpBeGVMaFN6NWMxUFdNWkVEcVhCVzlIYlNuRTR4IiwiaWF0IjoxNzA5NTcxNDk2LCJleHAiOjE3MDk1NzUwOTZ9.8kQjVibE5Z2YlBp7TXxqcdnkxOU1oUEw3qIeqpLvlQw; Max-Age=3600; Path=/; HttpOnly; Secure; SameSite=Strict; refreshToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwdWJsaWNLZXkiOiJhN1BReU1OWXhpa1VUNWpBeGVMaFN6NWMxUFdNWkVEcVhCVzlIYlNuRTR4IiwiaWF0IjoxNzA5NTcxNDk2LCJleHAiOjE3MDk2NTc4OTZ9.D1WBuRl6AtjRJiSTgZawqxIRBrL0n6CBCjv8sgWVIao; Max-Age=86400; Path=/; HttpOnly; Secure; SameSite=Strict;

so that the browser doesnt recognize it. I think sveltekit breaks it up into 2 set-cookie headers

@BearToCode
Copy link
Contributor Author

You're right! Can you provide an example of the headers SvelteKit generates with multiple cookies?

@shirecoding
Copy link

Yep this is what i get

Screenshot 2024-03-05 at 1 10 31 AM

instead of this

Set-Cookie: cookie1=value1; Expires=Wed, 09 Jun 2021 10:18:14 GMT; Path=/
Set-Cookie: cookie2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT; Path=/

@BearToCode
Copy link
Contributor Author

BearToCode commented Mar 4, 2024

Created a new PR for that! With that fix it works fine for me, but you can try it yourself and give your feedback!

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

Successfully merging this pull request may close these issues.

None yet

3 participants