-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ea227b
commit a917dd3
Showing
9 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...n/alddeul_babsang/app/DataSourceModule.kt → ...lddeul_babsang/app/di/DataSourceModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ackathon/alddeul_babsang/app/Extension.kt → ...athon/alddeul_babsang/app/di/Extension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.hackathon.alddeul_babsang.app | ||
package com.hackathon.alddeul_babsang.app.di | ||
|
||
fun String?.isJsonObject(): Boolean = this?.startsWith("{") == true && this.endsWith("}") | ||
fun String?.isJsonArray(): Boolean = this?.startsWith("[") == true && this.endsWith("]") |
6 changes: 5 additions & 1 deletion
6
...ackathon/alddeul_babsang/app/Qualifier.kt → ...athon/alddeul_babsang/app/di/Qualifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.hackathon.alddeul_babsang.app | ||
package com.hackathon.alddeul_babsang.app.di | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AlddeulRetrofit | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AccessToken | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class UserPreferences |
2 changes: 1 addition & 1 deletion
2
...n/alddeul_babsang/app/RepositoryModule.kt → ...lddeul_babsang/app/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...thon/alddeul_babsang/app/ServiceModule.kt → ...n/alddeul_babsang/app/di/ServiceModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...deul_babsang/app/UserPreferencesModule.kt → ...l_babsang/app/di/UserPreferencesModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/hackathon/alddeul_babsang/app/interceptor/TokenInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.hackathon.alddeul_babsang.app.interceptor | ||
|
||
import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class TokenInterceptor @Inject constructor( | ||
private val userPreferencesDataSource: UserPreferencesDataSource | ||
) : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response = runBlocking { | ||
val request = chain.request() | ||
val url = request.url.toString() | ||
|
||
// 특정 URL 패턴에 대해서는 토큰을 추가하지 않음 | ||
if (url.contains("/api/v1/auth/login") || | ||
url.contains("api/v1/signup") || | ||
url.contains("api/v1/member")) { | ||
// 로그인 요청 등 토큰이 필요 없는 요청의 경우 | ||
return@runBlocking chain.proceed(request) | ||
} | ||
|
||
// 토큰이 필요한 요청의 경우 | ||
val accessToken = userPreferencesDataSource.getUserAccessToken().first() | ||
val newRequest = request.newBuilder() | ||
.addHeader("Authorization", "Bearer $accessToken") | ||
.build() | ||
|
||
Timber.tag("interceptor").d("accessToken $accessToken") | ||
chain.proceed(newRequest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters