Class AuthenticationController

java.lang.Object
com.mindstore.backend.controller.AuthenticationController

@RequestMapping("/auth") @RestController public class AuthenticationController extends Object
REST controller for handling authentication endpoints. Provides login, registration, and JWT token-related operations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AuthenticationController(JwtService jwtService, AuthenticationService authenticationService)
    authentication controller class
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<LoginResponse>
    authenticate(LoginUserDto loginUserDto, jakarta.servlet.http.HttpServletResponse response)
    function: login a user and set a cookie
    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
    org.springframework.http.ResponseEntity<Void>
    logout(jakarta.servlet.http.HttpServletResponse response)
    function: log out a user, used in frontend to delete the set cookie
    org.springframework.http.ResponseEntity<User>
    register(RegisterUserDto registerUserDto)
    function: used to register users

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AuthenticationController

      public AuthenticationController(JwtService jwtService, AuthenticationService authenticationService)
      authentication controller class
      Parameters:
      jwtService - with jwt token
      authenticationService - 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 password
      response - 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