Skip to content

Commit

Permalink
[feat] : #8 AccessTokenInterceptor 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
1971123-seongmin committed Nov 6, 2024
1 parent 0a3bc75 commit 8d2e980
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.and.data.interceptor

import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.runBlocking
import okhttp3.Interceptor
import okhttp3.Response
import org.sopt.and.utils.TokenManger
import javax.inject.Inject

class AccessTokenInterceptor @Inject constructor(
private val tokenManager: TokenManger
) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val token = runBlocking { tokenManager.getAccessToken().firstOrNull() }
val request = chain.request().newBuilder().apply {
token?.let { addHeader(HEADER_AUTHORIZATION, it) }
}.build()
return chain.proceed(request)
}

companion object {
const val HEADER_AUTHORIZATION = "token"
}
}

0 comments on commit 8d2e980

Please sign in to comment.