
Release Notes: - N/A --------- Co-authored-by: michael <michael@zed.dev> Co-authored-by: agus <agus@zed.dev>
2.4 KiB
2.4 KiB
- Add a new test case in
create-client.test.ts
for when thereturnTo
option is provided during sign-out. It verifies that the sign-out URL includes the correctreturn_to
query parameter with the provided URL. The test sets up a mock client, calls signOut with a returnTo value, and asserts that the resulting URL contains the expected session_id and return_to parameters while maintaining the correct API endpoint structure. - Modifies the
signOut
method increate-client.ts
to accept an optional options parameter containing a returnTo string. Instead of directly passing the sessionId to getLogoutUrl, it now passes an object containing both the sessionId and the returnTo value from the options. The method maintains its existing behavior of checking for an access token and clearing session data when a URL is available. - Updates the HTTP client tests in
http-client.test.ts
to reflect the new getLogoutUrl signature. It adds a test case for the basic logout URL and a new describe block for when returnTo is provided, verifying that the URL includes the properly encoded return_to parameter. The test ensures the URL construction handles both cases correctly. - Modifies the
getLogoutUrl
method inhttp-client.ts
to accept an object parameter with sessionId and returnTo properties instead of just a sessionId string. It maintains the base URL construction but now conditionally adds the return_to query parameter only when a returnTo value is provided, while always including the session_id parameter. The method handles URL construction and parameter encoding internally. - Updates the session initialization logic in
create-client.ts
to check for either aworkos-has-session
cookie or a refresh token (retrieved viagetRefreshToken
). This allows the client to refresh sessions even if nocode
is present in the URL, especially in development environments. - Adds corresponding test coverage in
create-client.test.ts
:- When no code is in the URL but the
workos-has-session
cookie exists, the session should be refreshed. - When devMode is enabled and a refresh token is present in localStorage, the session should be refreshed.
- When devMode is enabled but no refresh token exists, the client should be created without making any network requests.
- When neither a code, cookie, nor refresh token is present, the client should initialize without refreshing.
- When no code is in the URL but the