Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/web/src/runtime/native-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ export async function waitForNativeSessionCookie(): Promise<void> {
* same code works across environments without runtime host sniffing.
*/
export function installSessionCookies(sessionToken: string): void {
const cookieAttrs = "path=/; domain=.vellum.ai; secure; samesite=lax";
// `max-age` makes the cookie persistent. If unspecified, the cookie
// expires at the end of the session, and users will be required to
// login again.
const cookieAttrs = "path=/; domain=.vellum.ai; secure; samesite=lax; max-age=1209600";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear the persistent session cookie on logout failures

This makes the JS-installed native session cookie survive cold restarts, but the web logout path only calls allauthLogout() best-effort and then clears local state in finally (apps/web/src/stores/auth-store.ts:243-251), even if the DELETE fails/returns non-ok and therefore no server Set-Cookie expiry is applied. In that offline/server-error scenario an iOS user appears signed out and is redirected to login, but after reopening the app the now-persistent valid cookie logs them back in; either explicitly expire these cookie names during logout cleanup or avoid persisting them without a matching client-side clear path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor edge case that I'm not gonna address here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we're manually reinstalling cookies. Why not just use X-Session-Token for auth, like with macOS?

As is, this requires us to keep all of these attributes in sync with the actual cookie, but we're not doing properly right now:

  • domain is wrong. This should be same-host and not be made available on all subdomains
  • max-age also needs to be kept in sync with backend in case we tweak default expiry

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @noanflaherty in case this has implications for electron

document.cookie = `sessionid=${sessionToken}; ${cookieAttrs}`;
document.cookie = `__Secure-sessionid=${sessionToken}; ${cookieAttrs}`;
Comment on lines 187 to 188

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only set one of these cookies, not both. Public SPA is served over HTTPS and should use the __Secure prefix

}
Expand Down