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

When you perform a server action and there is a navigate the defined headers on response gets lost #251

Closed
AlbertSabate opened this issue Jun 17, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@AlbertSabate
Copy link
Collaborator

Example:

async function submitForm(
  e: JSX.TargetedSubmitEvent<EventTarget> & { formData: FormData },
  req: RequestContext,
) {
  setCookie(req, 'access-token', responseData.data.accessToken, { expires });
  navigate('/');
}

const Component = () => <form onSubmit={submitForm} />;

The cookie 'access-token' should be defined, but it's not.

@aralroca aralroca self-assigned this Jun 17, 2024
@aralroca aralroca added the bug Something isn't working label Jun 17, 2024
@AlbertSabate AlbertSabate changed the title When you perform a server action and there is a navigate the defined headers on request gets lost When you perform a server action and there is a navigate the defined headers on response gets lost Jun 17, 2024
@aralroca
Copy link
Collaborator

aralroca commented Jun 17, 2024

I don't know at what point it is an issue or it is better to create a feature of Brisa, cookies should be added to the response and not to the request.

@AlbertSabate
Copy link
Collaborator Author

Yep, correct. That was my fault. I meant response. So as you mentioned I followed https://brisa-mu.vercel.app/building-your-application/routing/middleware#on-response and make it work.

Example:

export function responseHeaders(req: RequestContext) {
  const headers: Record<string, string> = {};
  const accessToken = req.store.get('access-token') as string | undefined;
  if (accessToken) {
    const expires = new Date();
    expires.setTime(expires.getTime() + 518_400_000); // Cookie will expire in 6d
    headers['set-cookie'] = setCookie('access-token', accessToken, undefined, { expires });
  }

  return headers;
}

@aralroca
Copy link
Collaborator

For now we keep the responseHeaders to modify the headers of the actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants