Hide private profile data and reissue tokens when users change their login

- GET /api/v1/users/{id} returns email and phone only to the user themself
  and to admins.
- When a user changes their own login, the PUT response carries a new token
  pair (login is the JWT subject, so the old tokens stop matching); old
  refresh tokens fail on their own because the stored login differs.
- The old avatar is deleted only after the profile is saved; login length is
  checked against the column size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-20 01:32:13 +03:00
parent 48351398b5
commit 477737c161
3 changed files with 138 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
package com.krylov.refound.dto.user;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.krylov.refound.enums.Role;
import lombok.Builder;
import lombok.Data;
@@ -15,4 +16,13 @@ public class UserResponseDto {
private String email;
private String avatar;
private Role role;
/**
* Новая пара токенов — только в ответе PUT /api/v1/users/{id}, когда пользователь
* сменил свой логин (логин — subject JWT, прежние токены больше не подходят).
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
private String token;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String refreshToken;
}