Giter Club home page Giter Club logo

Comments (7)

wbinarytree avatar wbinarytree commented on August 28, 2024 3

I'm using full kotlin and meet the problem.
It turns out we don't have a persistent property always false to won't be saved in SharedPref.
After I rewrite the method saveFromResponse to force save it. It works fine.
related issue #14 #15

from persistentcookiejar.

Serhii-the-Dev avatar Serhii-the-Dev commented on August 28, 2024 2

I've also faced that problem, and in my case it was related to Kotlin object declaration. So if you also using an object as a fabric of Retrofit APIs, you can bypass the issue using by lazy delegate.
Since I came here looking for solution, maybe my example will help a next wanderer:

object HttpApi {
    lateinit private var cookiesHandler: CookieJar

    fun updateCookieJarWithContext(context: Context) {
        cookiesHandler = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(context))
    }

    private val loggingInterceptor by lazy {
        HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY }
    }

    private val httpClient by lazy {
        OkHttpClient.Builder().apply {
            addInterceptor(loggingInterceptor)
            cookieJar(cookiesHandler)
        }.build()
    }

    private val builder by lazy { Retrofit.Builder().addConverterFactory(JacksonConverterFactory.create()) }

    private fun <ApiInterface> createService(serviceClass: Class<ApiInterface>, apiEndpointUrl: String = "rest") = builder
            .baseUrl("https://***/$apiEndpointUrl/")
            .client(httpClient)
            .build()
            .create(serviceClass)

    val rest: HttpRestApi by lazy { createService(HttpRestApi::class.java) }
    val auth: HttpAuth by lazy { createService(HttpAuth::class.java, "auth") }
}

Also I recommend to use a dependency injection framework, like Dagger, there is an example of application context injection.

from persistentcookiejar.

tmdroid avatar tmdroid commented on August 28, 2024 1

@franmontiel why not just have an option to save all cookies regardless if they have max-age or expires attributes? Seems like this persistence thing is causing many people problems with your library including myself. I'm using Kotlin and building a login flow where I store some cookies from a request, navigate to a 3rd party app for logging in and then come back to my original app, and then to my surprise, some important cookies are lost.

from persistentcookiejar.

franmontiel avatar franmontiel commented on August 28, 2024

I`m sorry I have no info about this problem, If you wish you can track it down and let us know your discoveries

from persistentcookiejar.

alanum avatar alanum commented on August 28, 2024

i got the same problem ...cry!!!

from persistentcookiejar.

jiangecho avatar jiangecho commented on August 28, 2024

got the same problem +1

from persistentcookiejar.

a2open avatar a2open commented on August 28, 2024

I also encountered the same problem in Kotlin

from persistentcookiejar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.