Package com.mindstore.backend.controller
Class AuthenticationController
java.lang.Object
com.mindstore.backend.controller.AuthenticationController
REST controller for handling authentication endpoints.
Provides login, registration, and JWT token-related operations.
-
Constructor Summary
ConstructorsConstructorDescriptionAuthenticationController(JwtService jwtService, AuthenticationService authenticationService) authentication controller class -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<LoginResponse> authenticate(LoginUserDto loginUserDto, jakarta.servlet.http.HttpServletResponse response) function: login a user and set a cookieorg.springframework.http.ResponseEntity<?> checkAuth(jakarta.servlet.http.HttpServletRequest request) function: check if a user is currently logged in for example when setting the login state in the frontend returns the token, and the time left for the token validityorg.springframework.http.ResponseEntity<Void> logout(jakarta.servlet.http.HttpServletResponse response) function: log out a user, used in frontend to delete the set cookieorg.springframework.http.ResponseEntity<User> register(RegisterUserDto registerUserDto) function: used to register users
-
Constructor Details
-
AuthenticationController
authentication controller class- Parameters:
jwtService- with jwt tokenauthenticationService- used for authenticating functions
-
-
Method Details
-
register
@PostMapping("/signup") public org.springframework.http.ResponseEntity<User> register(@RequestBody RegisterUserDto registerUserDto) function: used to register users- Parameters:
registerUserDto- the Dto with user data- Returns:
- ok --> if successfull
-
checkAuth
@GetMapping("/check") public org.springframework.http.ResponseEntity<?> checkAuth(jakarta.servlet.http.HttpServletRequest request) function: check if a user is currently logged in for example when setting the login state in the frontend returns the token, and the time left for the token validity- Parameters:
request- the path that the user tries to access- Returns:
- ok --> if successfull, else return 401 Unauthorized
-
authenticate
@PostMapping("/login") public org.springframework.http.ResponseEntity<LoginResponse> authenticate(@RequestBody LoginUserDto loginUserDto, jakarta.servlet.http.HttpServletResponse response) function: login a user and set a cookie- Parameters:
loginUserDto- with the email and passwordresponse- the extended response- Returns:
- ok ---> if successfull
-
logout
@PostMapping("/logout") public org.springframework.http.ResponseEntity<Void> logout(jakarta.servlet.http.HttpServletResponse response) function: log out a user, used in frontend to delete the set cookie- Parameters:
response- - the extended response- Returns:
- ok ---> if successfull
-