Bug with token refresh causing 500 internal server error seems to be fixed by locking the RefreshToken entity.
This commit is contained in:
parent
66242845d6
commit
0396e8e3b0
@ -2,6 +2,7 @@ package app.mealsmadeeasy.api.auth;
|
|||||||
|
|
||||||
import app.mealsmadeeasy.api.jwt.JwtService;
|
import app.mealsmadeeasy.api.jwt.JwtService;
|
||||||
import app.mealsmadeeasy.api.user.UserEntity;
|
import app.mealsmadeeasy.api.user.UserEntity;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
@ -14,7 +15,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public final class AuthServiceImpl implements AuthService {
|
public class AuthServiceImpl implements AuthService {
|
||||||
|
|
||||||
private final AuthenticationManager authenticationManager;
|
private final AuthenticationManager authenticationManager;
|
||||||
private final JwtService jwtService;
|
private final JwtService jwtService;
|
||||||
@ -60,11 +61,13 @@ public final class AuthServiceImpl implements AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void logout(String refreshToken) {
|
public void logout(String refreshToken) {
|
||||||
this.refreshTokenRepository.findByToken(refreshToken).ifPresent(this.refreshTokenRepository::delete);
|
this.refreshTokenRepository.findByToken(refreshToken).ifPresent(this.refreshTokenRepository::delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public LoginDetails refresh(@Nullable String refreshToken) throws LoginException {
|
public LoginDetails refresh(@Nullable String refreshToken) throws LoginException {
|
||||||
if (refreshToken == null) {
|
if (refreshToken == null) {
|
||||||
throw new LoginException(LoginExceptionReason.NO_REFRESH_TOKEN, "No refresh token provided.");
|
throw new LoginException(LoginExceptionReason.NO_REFRESH_TOKEN, "No refresh token provided.");
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package app.mealsmadeeasy.api.auth;
|
package app.mealsmadeeasy.api.auth;
|
||||||
|
|
||||||
|
import jakarta.persistence.LockModeType;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Lock;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface RefreshTokenRepository extends JpaRepository<RefreshTokenEntity, Long> {
|
public interface RefreshTokenRepository extends JpaRepository<RefreshTokenEntity, Long> {
|
||||||
|
|
||||||
|
@Lock(LockModeType.PESSIMISTIC_READ)
|
||||||
Optional<RefreshTokenEntity> findByToken(String token);
|
Optional<RefreshTokenEntity> findByToken(String token);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user