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

Setting cookie prefixes host_key with a period #181

Open
Thenlie opened this issue Aug 31, 2023 · 3 comments
Open

Setting cookie prefixes host_key with a period #181

Thenlie opened this issue Aug 31, 2023 · 3 comments

Comments

@Thenlie
Copy link

Thenlie commented Aug 31, 2023

  if (Platform.OS === 'android') {
    CookieManager.set(
      'https://attendee-login-service-dev.us-east-1.lb.com/attendee-login',
      {
        name: 'AttendeeLoginOAuthToken',
        value: 'test',
        domain: 'attendee-login-service-dev.us-east-1.lb.com',
        path: '/attendee-login',
        version: 1,
        expires: '2023-09-01T00:00:00.00'
      }
    ).then(success => {
      if (success) LOG.debug('CookieManager.set =>', success);
      else LOG.error('CookieManager.set =>', success);
    });
  }

I am using this snippet and attempting to overwrite a cookie that already exists. My hope is that it will update the value to whatever is passed in the value field.

Expected: Update the existing cookie value to test
Actual: Creates a new cookie with the key .attendee-login-service-dev.us-east-1.lb.com

image

I am unsure why the period is being added to the start of the domain. Can anyone shed some light?

@jakubboguski
Copy link

Hi @Thenlie, would you like to share how you solved this? Thanks!

@Thenlie
Copy link
Author

Thenlie commented Mar 26, 2024

@jakubboguski I ended up using setFromResponse. So my final code looks like this:

if (Platform.OS === 'android') {
  const now = new Date();
  const tomorrow = new Date(now.getTime() + 86400000); // +1 day in ms
  const { loginService } = getConfig(environment);

  const res = await CookieManager.setFromResponse(
    loginService.url,
    `AttendeeLoginOAuthToken=hidden; path=/attendee-login; expires=${tomorrow.toUTCString()}; secure; HttpOnly`
  );
  if (res) LOG.debug('CookieManager setFromResponse success!');
  else LOG.error('CookieManager setFromResponse failed!');
}

I still don't understand the cause of the original issue here, but this seemed like a useable workaround for my case.

@jakubboguski
Copy link

jakubboguski commented Mar 27, 2024

I ended up with the same solution (for android). I noticed also that setFromResponse couldn't set domain in any way.

Thanks for the quick reply @Thenlie

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

2 participants