suspend coroutines
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package space.luminic.budgerapp.services
|
||||
|
||||
import org.springframework.cache.annotation.CacheEvict
|
||||
import org.springframework.stereotype.Service
|
||||
import reactor.core.publisher.Mono
|
||||
@@ -25,15 +26,12 @@ class TokenService(private val tokenRepository: TokenRepo) {
|
||||
return tokenRepository.findByToken(token)
|
||||
}
|
||||
|
||||
@CacheEvict("tokens", allEntries = true)
|
||||
fun revokeToken(token: String): Mono<Void> {
|
||||
return tokenRepository.findByToken(token)
|
||||
.switchIfEmpty(Mono.error(Exception("Token not found")))
|
||||
.flatMap { existingToken ->
|
||||
val updatedToken = existingToken.copy(status = TokenStatus.REVOKED)
|
||||
tokenRepository.save(updatedToken).then()
|
||||
}
|
||||
|
||||
fun revokeToken(token: String) {
|
||||
val tokenDetail =
|
||||
tokenRepository.findByToken(token).block()!!
|
||||
val updatedToken = tokenDetail.copy(status = TokenStatus.REVOKED)
|
||||
tokenRepository.save(updatedToken).block()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user