Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/fcgl/madrid/MadridApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.fcgl.madrid.user.configuration.AppProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@EnableEurekaClient
@SpringBootApplication
@EnableConfigurationProperties(AppProperties.class)
public class MadridApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
public class AuthResponse {
private String accessToken;
private String tokenType = "Bearer";
private String userId;

public AuthResponse(String accessToken) {
public AuthResponse(String accessToken, String userId) {
this.accessToken = accessToken;
this.userId = userId;
}

public String getAccessToken() {
Expand All @@ -24,5 +26,13 @@ public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

// Getters and Setters (Omitted for brevity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public AuthResponse getResponse() {
public void setResponse(AuthResponse response) {
this.response = response;
}

}
5 changes: 4 additions & 1 deletion src/main/java/com/fcgl/madrid/user/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fcgl.madrid.user.payload.response.LoginResponse;
import com.fcgl.madrid.user.repository.UserRepository;
import com.fcgl.madrid.user.security.TokenProvider;
import com.fcgl.madrid.user.security.UserPrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -68,7 +69,9 @@ public ResponseEntity<LoginResponse> authenticateUser(LoginRequest loginRequest)
SecurityContextHolder.getContext().setAuthentication(authentication);

String token = tokenProvider.createToken(authentication);
AuthResponse authResponse = new AuthResponse(token);
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
String userId = Long.toString(userPrincipal.getId());
AuthResponse authResponse = new AuthResponse(token, userId);
LoginResponse response = new LoginResponse(InternalStatus.OK, authResponse);
return new ResponseEntity<LoginResponse>(response ,HttpStatus.OK);
}
Expand Down