From f038fe9f1eafa814871bddb1a1058833a1c93877 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 19 Apr 2024 17:25:52 +0200 Subject: [PATCH] Make sure we do not send stale tokens on iOS --- .../androidmakers/store/graphql/ApolloClient.android.kt | 7 +++++++ .../kotlin/fr/androidmakers/store/graphql/ApolloClient.kt | 4 +++- .../fr/androidmakers/store/graphql/ApolloClient.ios.kt | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.android.kt create mode 100644 shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.ios.kt diff --git a/shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.android.kt b/shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.android.kt new file mode 100644 index 00000000..e20716fd --- /dev/null +++ b/shared/data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.android.kt @@ -0,0 +1,7 @@ +package fr.androidmakers.store.graphql + +import fr.androidmakers.domain.repo.UserRepository + +actual suspend fun getIdToken(userRepository: UserRepository): String? { + return userRepository.getIdToken() +} \ No newline at end of file diff --git a/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt b/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt index 0f15e951..8a186b56 100644 --- a/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt +++ b/shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt @@ -10,6 +10,8 @@ import com.apollographql.apollo3.network.http.HttpInterceptor import com.apollographql.apollo3.network.http.HttpInterceptorChain import fr.androidmakers.domain.repo.UserRepository +expect suspend fun getIdToken(userRepository: UserRepository): String? + fun ApolloClient( sqlNormalizedCacheFactory: SqlNormalizedCacheFactory, userRepository: UserRepository, @@ -25,7 +27,7 @@ fun ApolloClient( /** * */ - val token = userRepository.getIdToken() + val token = getIdToken(userRepository) if (token != null) { addHeader("Authorization", "Bearer $token") } diff --git a/shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.ios.kt b/shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.ios.kt new file mode 100644 index 00000000..949aadbc --- /dev/null +++ b/shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.ios.kt @@ -0,0 +1,8 @@ +package fr.androidmakers.store.graphql + +import fr.androidmakers.domain.repo.UserRepository + +actual suspend fun getIdToken(userRepository: UserRepository): String? { + // We do not support signin on iOS? make sure that we're not sending a stale token + return null +} \ No newline at end of file