Skip to content

Commit

Permalink
[feat] #8 Auth Interceptor 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HAJIEUN02 committed Nov 4, 2024
1 parent abfaeab commit d471261
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/src/main/java/org/sopt/and/data/interceptor/AuthInterceptor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.and.data.interceptor

import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import org.sopt.and.data.datasource.local.WaveLocalDataSource
import javax.inject.Inject

class AuthInterceptor @Inject constructor(
private val localStorage: WaveLocalDataSource
) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
val authRequest =
if (localStorage.isLogin) originalRequest.newAuthBuilder() else originalRequest
return chain.proceed(authRequest)
}

private fun Request.newAuthBuilder() =
this.newBuilder().addHeader(AUTHORIZATION, localStorage.accessToken).build()

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

0 comments on commit d471261

Please sign in to comment.