Skip to content

fix(ios): use persistent WKWebsiteDataStore so cookies survive cold launch#140

Open
sawan-webmavens wants to merge 1 commit into
NativePHP:mainfrom
sawan-webmavens:fix/ios-persistent-cookies
Open

fix(ios): use persistent WKWebsiteDataStore so cookies survive cold launch#140
sawan-webmavens wants to merge 1 commit into
NativePHP:mainfrom
sawan-webmavens:fix/ios-persistent-cookies

Conversation

@sawan-webmavens
Copy link
Copy Markdown

Summary

Why

WKWebsiteDataStore.nonPersistent() is in-memory storage — the WKWebView starts with an empty cookie jar on every cold launch. For Laravel apps this wipes the laravel_session cookie, so even though the session file is still on disk in storage/framework/sessions/, Laravel can't find it. The user appears signed-out, and any session(...) state (auth user, flash messages, dismissed prompts) is reset.

Android already does the right thing — CookieManager.getInstance() is persistent and shared by default. Same Laravel code, two different behaviors. This patch brings iOS in line.

Risk

WKWebsiteDataStore.default() is the shared, app-wide persistent jar. Not an issue for NativePHP apps (they own their entire WebView), but flagging in case reviewers want it on the radar.

Test plan

  • Cold-launch a NativePHP iOS app that signs the user in via Laravel auth. Confirm auth()->check() is true on next cold launch (was false before this change).
  • Confirm session(...) state survives cold launch.
  • Verify behavior matches Android same-app behavior.

Notes

Refs #139, which raised the open question of unconditional flip vs. config option. This PR is the unconditional flip — happy to amend to a config option (e.g. 'cookies' => 'persistent'|'ephemeral' defaulting to persistent) if you'd rather preserve the current behavior as an opt-in.

…aunch

WKWebsiteDataStore.nonPersistent() is in-memory storage. The WKWebView
starts with an empty cookie jar on every cold launch, which wipes the
laravel_session cookie and makes the user appear signed-out even though
their session file is still on disk.

Android already uses persistent storage via CookieManager.getInstance(),
so this aligns iOS with Android behavior.

Refs NativePHP#139
@simonhamp
Copy link
Copy Markdown
Member

I think it's right to have consistent behaviour across both platforms 👍🏼

My caveat is that I think cookies as a mechanism for determining authenticated state is kind of "wrong" (convenient, but not as secure as secure storage) in this context and the fact that Android supports it actually suggests, imo, that it's Android that should change to align with iOS.

Just my opinion tho and some history on why I chose for iOS cookie jars to be in-memory only in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants