Skip to content

[Question]: JWT keeps expiring in background despite alwaysAutoRefresh=true on Supabase 3.1.4 #907

@Yahouedeou

Description

@Yahouedeou

General info

What is your question?

Problem

I'm experiencing frequent JWT expiration issues in my Android application that primarily runs in the background. Despite configuring alwaysAutoRefresh = true, and enableLifecycleCallbacks = false, sessions aren't consistently refreshed when the app is in background state.

Configuration

I'm using Supabase version 3.1.4 with Kotlin. Here's my client configuration:

val client by lazy {
    createSupabaseClient(
        supabaseUrl = SUPABASE_URL,
        supabaseKey = SUPABASE_KEY
    ) {
        defaultSerializer = KotlinXSerializer(json)
        install(Postgrest)
        install(Realtime)
        install(Auth) {
           alwaysAutoRefresh = true          
           enableLifecycleCallbacks = false
        }
        install(Functions)
    }
}

Questions

  • Is there a recommended approach for handling token refreshing in Android apps that spend significant time in background state?
  • Are there specific configuration options I'm missing to make the built-in refresh mechanism work properly in background?

Relevant log output (optional)

Error updating request status | Error: io.github.jan.supabase.postgrest.exception.PostgrestRestException: JWT expired
URL: https://XXXX.supabase.co/rest/v1/device_health_commands?id=eq.XXXX-XXXX&select=%2A
Headers: [Authorization=[Bearer XXXXXXXXXXXX], Prefer=[return=representation], Content-Profile=[public], apikey=[XXXXXXXXXXXX], X-Client-Info=[supabase-kt/3.1.4], Accept=[application/json], Accept-Charset=[UTF-8]]
Http Method: PATCH

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions