Skip to content

Commit 8d48bdc

Browse files
authored
support secure cookie option for identity cookies (#577)
* support secure cookie option for identity cookies * add changeset
1 parent 48f3c0b commit 8d48bdc

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

.changeset/dry-vans-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
Fixes an issue where the 'secure' cookie setting was not being applied correctly when specified.

packages/browser/src/core/user/__tests__/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,22 @@ describe('user', () => {
513513
expect(cookie['options'].domain).toBe('foo')
514514
expect(cookie['options'].secure).toBe(true)
515515
expect(cookie['options'].path).toBe('/test')
516+
expect(cookie['options'].secure).toBe(true)
517+
})
518+
519+
it('should pass options when creating cookie', () => {
520+
const jarSpy = jest.spyOn(jar, 'set')
521+
const cookie = new Cookie({ domain: 'foo', secure: true, path: '/test' })
522+
523+
cookie.set('foo', 'bar')
524+
525+
expect(jarSpy).toHaveBeenCalledWith('foo', 'bar', {
526+
domain: 'foo',
527+
expires: 365,
528+
path: '/test',
529+
sameSite: 'Lax',
530+
secure: true,
531+
})
516532
})
517533
})
518534

packages/browser/src/core/user/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class Cookie extends Store {
9292
expires: this.options.maxage,
9393
domain: this.options.domain,
9494
path: this.options.path,
95+
secure: this.options.secure,
9596
}
9697
}
9798

0 commit comments

Comments
 (0)