-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only request token endpoint initially, then use a cookie to determine…
… if there is an authenticated user (#1740) * Create readable client side cookie to determine login state * Fix cookie being set when it shouldn't and fix reset cookie * Rename has token key * Update cookie name in toolbar * Update variable names * mergeCookies function and properly set expires and maxage * Remove `removeCookie` in favor of `setCookie` * Add `getHeader` to mocked test responses * Add unit tests * Add changeset * Update .changeset/brave-cougars-lie.md Co-authored-by: Matthew Wright <1815200+matthewguywright@users.noreply.github.com> --------- Co-authored-by: Matthew Wright <1815200+matthewguywright@users.noreply.github.com>
- Loading branch information
1 parent
2b3da86
commit 0759959
Showing
9 changed files
with
340 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@faustwp/core': patch | ||
--- | ||
|
||
Fixed the behavior of a request to the `api/faust/auth/token` endpoint on every page load when the toolbar is enabled. We now set a `WP_URL-has-rt` token with a `0` or `1` value that can be read client side (aka, not an `httpOnly` cookie) for determining if there is a logged in user or not. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { mergeCookies } from '../../../src/server/auth/cookie'; | ||
|
||
describe('mergeCookies', () => { | ||
it('merges cookies from an existing setCookie header and a new cookie', () => { | ||
const existingSetCookieHeader = `http://headless.local-rt=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure`; | ||
const newCookie = `http://headless.local-has-rt=0; Max-Age=2592000; Path=/`; | ||
const result = mergeCookies(existingSetCookieHeader, newCookie); | ||
|
||
expect(result).toStrictEqual([existingSetCookieHeader, newCookie]); | ||
}); | ||
|
||
it('returns the cookie if existing set cookie header does not exist', () => { | ||
const newCookie = `http://headless.local-has-rt=0; Max-Age=2592000; Path=/`; | ||
|
||
expect(mergeCookies(undefined, newCookie)).toStrictEqual(newCookie); | ||
}); | ||
|
||
it('merges cookies from an existing array of setCookies', () => { | ||
const existingSetCookieHeader = [ | ||
`http://headless.local-rt=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure`, | ||
`http://testing.local-rt=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure`, | ||
]; | ||
const newCookie = `http://headless.local-has-rt=0; Max-Age=2592000; Path=/`; | ||
const result = mergeCookies(existingSetCookieHeader, newCookie); | ||
|
||
expect(result).toStrictEqual([...existingSetCookieHeader, newCookie]); | ||
}); | ||
}); |
Oops, something went wrong.