-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make redirect URI available evia either env variables or via middleware config * Add version bump
- Loading branch information
Showing
6 changed files
with
44 additions
and
27 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
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { WORKOS_REDIRECT_URI, WORKOS_COOKIE_MAX_AGE, WORKOS_COOKIE_DOMAIN } from './env-variables.js'; | ||
import { CookieOptions } from './interfaces.js'; | ||
|
||
const redirectUrl = new URL(WORKOS_REDIRECT_URI); | ||
const isSecureProtocol = redirectUrl.protocol === 'https:'; | ||
export function getCookieOptions(redirectUri?: string | null): CookieOptions { | ||
const url = new URL(redirectUri || WORKOS_REDIRECT_URI); | ||
|
||
const cookieOptions = { | ||
path: '/', | ||
httpOnly: true, | ||
secure: isSecureProtocol, | ||
sameSite: 'lax' as const, | ||
// Defaults to 400 days, the maximum allowed by Chrome | ||
// It's fine to have a long cookie expiry date as the access/refresh tokens | ||
// act as the actual time-limited aspects of the session. | ||
maxAge: WORKOS_COOKIE_MAX_AGE ? parseInt(WORKOS_COOKIE_MAX_AGE, 10) : 60 * 60 * 24 * 400, | ||
domain: WORKOS_COOKIE_DOMAIN, | ||
}; | ||
|
||
export { cookieOptions }; | ||
return { | ||
path: '/', | ||
httpOnly: true, | ||
secure: url.protocol === 'https:', | ||
sameSite: 'lax' as const, | ||
// Defaults to 400 days, the maximum allowed by Chrome | ||
// It's fine to have a long cookie expiry date as the access/refresh tokens | ||
// act as the actual time-limited aspects of the session. | ||
maxAge: WORKOS_COOKIE_MAX_AGE ? parseInt(WORKOS_COOKIE_MAX_AGE, 10) : 60 * 60 * 24 * 400, | ||
domain: WORKOS_COOKIE_DOMAIN, | ||
}; | ||
} |
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