ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.06k stars 1k forks source link

bug: Persistent Cookie Storage Issue in iOS App #6715

Closed Nasmar closed 1 year ago

Nasmar commented 1 year ago

Bug Report

Capacitor Version

Latest Dependencies:       

  @capacitor/cli: 5.1.1    
  @capacitor/core: 5.1.1   
  @capacitor/android: 5.1.1
  @capacitor/ios: 5.1.1    

Installed Dependencies:    

  @capacitor/cli: 5.0.4    
  @capacitor/core: 5.0.4   
  @capacitor/ios: 5.0.4    
  @capacitor/android: 5.0.4

Platform(s)

iOS

Current Behavior

We cannot achieve persistent storage of HttpOnly cookies in our iOS app using CapacitorCookies and CapacitorHttp plugins.

Our app successfully retains cookies and functions as intended under normal usage. However, when the app is terminated and restarted, it fails to remember the cookies, resulting in users being prompted to log in again.

Note that our Android app functions correctly, retaining the cookies as intended.

We are utilizing the native Capacitor Http module to make API calls.

Expected Behavior

When shutting the iOS app down, we expect that the app can retain the http only cookie to use our cookie authentication

Code Reproduction

import { CapacitorHttp, type HttpResponse } from '@capacitor/core';
const options = {
        url: url,
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        data: JSON.stringify(postdata),
        options: {
          webFetchExtra: {
            credentials: "include",
          },
        }
      };

const response: HttpResponse = await CapacitorHttp.post(options);
const resultAsJson = await JSON.parse(JSON.stringify(response)).data

capacitor.config.ts:

  appId: 'com.XXXX.app',
  appName: 'XXXX',
  webDir: 'dist',
  plugins: {
    CapacitorHttp: {
      enabled: true // This provides native http service support via patching fetch and XMLHttpRequest
    },
    CapacitorCookies: {
      enabled: true
    }
  }

Info.plist:

    <key>WKAppBoundDomains</key>
    <array>
        <string>XXXX.XXXX.XX</string>
    <string>XXXX.XXXX.XX/api/</string>
    <string>https://XXXX.XXXX.XX/</string>
        <string>https://XXXX.XXXX.XX/api/</string>
    </array>

Other Technical Details

npm --version output: 9.6.7

node --version output: 20.3.0

pod --version output (iOS issues only): 1.12.1

ionitron-bot[bot] commented 1 year ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue. Please see the Contributing Guide for how to create a Code Reproduction. Thanks! Ionitron 💙

markemer commented 1 year ago

Can you upload a sample project that we can use to test?

jcesarmobile commented 1 year ago

closing due to the lack of reproduction

Nasmar commented 1 year ago

I will make a sample project on it. Should i repost or is it fine here?

robmarshall commented 1 year ago

I am also having this issue.

Nasmar commented 1 year ago

@robmarshall look here for the solution https://github.com/ionic-team/capacitor/issues/6809

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.