fix: Specify the bypassed urls properly, with method
This commit is contained in:
parent
29f63d85c1
commit
db4fc34fe7
|
@ -27,23 +27,36 @@ class AuthInterceptor(
|
|||
}
|
||||
|
||||
companion object {
|
||||
// List of URLs to bypass in the interceptor
|
||||
private val bypassedUrls = listOf(
|
||||
"/ping",
|
||||
"/auth/login",
|
||||
"/auth/refresh",
|
||||
"/auth/logout"
|
||||
// Map of HTTP methods to their respective paths to bypass
|
||||
//
|
||||
// These are either unauthorized endpoints (don't need auth)
|
||||
// or endpoints which require a refresh token header, not access token
|
||||
// (The refresh token is then passed as a param in the service func call)
|
||||
private val bypassedUrls = mapOf(
|
||||
"GET" to listOf(
|
||||
"/ping",
|
||||
"/session"
|
||||
),
|
||||
"POST" to listOf(
|
||||
"/auth/login",
|
||||
"/auth/logout",
|
||||
"/auth/refresh",
|
||||
"/users",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val originalRequest = chain.request()
|
||||
val method = originalRequest.method()
|
||||
val path = originalRequest.url().encodedPath()
|
||||
|
||||
// Check if the request URL is in the bypass list
|
||||
if (bypassedUrls.any { originalRequest.url().encodedPath() == it }) {
|
||||
return chain.proceed(originalRequest)
|
||||
// Check if the method-path combination is in the bypass list
|
||||
bypassedUrls[method]?.let { paths ->
|
||||
if (paths.contains(path)) {
|
||||
return chain.proceed(originalRequest)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// No point in continuing if our refresh token expired, make the user to re-login
|
||||
|
|
Loading…
Reference in a new issue