title: How to keep user logged in on WKWebview in SwiftUI
body: <p>I have a website that asks for login in initial page and I would like to have users stay logged in so they don't have to input the login info every time they turn on the app.</p>
  <p>Here is my current code for calling WKWebkit. It does everything I need it to do except for the login session keeping part.</p>
  <pre><code>import SwiftUI
  import WebKit
  
  struct Webview: UIViewRepresentable {
  
  var url: String
  
  func makeUIView(context: Context) -&gt; WKWebView {
      guard let url = URL(string: self.url) else {
          return WKWebView()
      }
      let request = URLRequest(url:url)
      let wkWebview = WKWebView()
      wkWebview.load(request)
      return wkWebview
  }
  
  func updateUIView(_ uiView: WKWebView, context:
      UIViewRepresentableContext&lt;Webview&gt;) {
      
      }
  }
  </code></pre>
  <p>and I call it on ContentView like</p>
  <pre><code>Webview(url: &quot;https://example.com&quot;)
  </code></pre>
  <p>I have read developer documentation and searched gist, SO, and apple forum for managing login session/cookie in WKWebview.</p>
  <p>Some of the links I have tried implement in my code, but ending at ground zero are below:</p>
  <p><a href="https://stackoverflow.com/questions/50974353/wkwebview-setting-cookie-not-possible-ios-11/53057088#53057088">WKWebView setting Cookie not possible (iOS 11+)</a></p>
  <p><a href="https://developer.apple.com/forums/thread/99674" rel="nofollow noreferrer">https://developer.apple.com/forums/thread/99674</a></p>
  <p><a href="https://gist.github.com/skagedal/cd516751e655263218f1cad0281e9941" rel="nofollow noreferrer">https://gist.github.com/skagedal/cd516751e655263218f1cad0281e9941</a></p>
  <p><a href="https://medium.com/dev-genius/how-to-get-cookies-from-wkwebview-and-uiwebview-in-swift-46e1a072a606" rel="nofollow noreferrer">https://medium.com/dev-genius/how-to-get-cookies-from-wkwebview-and-uiwebview-in-swift-46e1a072a606</a></p>
  <p><a href="https://stackoverflow.com/a/26577303/15047236">https://stackoverflow.com/a/26577303/15047236</a></p>
  <p>I have tried numerous other source codes that I can read/understand what they do for past 2 weeks in vain.</p>
  <p>Please help this poor soul out.</p>