Class AuthController

java.lang.Object
com.nicholasalfonso.lato.controller.AuthController

@RestController @RequestMapping("/api/auth") public class AuthController extends Object
REST controller for user authentication and account management. Provides endpoints for registration, login, logout, token refresh, and account deletion.
  • Constructor Details

    • AuthController

      public AuthController(AuthService authService, CurrentUserService currentUserService)
      Creates the auth controller with required services.
      Parameters:
      authService - service for authentication operations
      currentUserService - service to resolve the current authenticated user
  • Method Details

    • handleRegistrationRequest

      @PostMapping("/register") public AuthResponse handleRegistrationRequest(@Valid @RequestBody @Valid RegisterRequest request, jakarta.servlet.http.HttpServletResponse response)
      Handles user registration requests.
      Parameters:
      request - registration details
      response - HTTP response to set cookie
      Returns:
      authentication response with tokens and user info
    • handleLoginRequest

      @PostMapping("/login") public AuthResponse handleLoginRequest(@Valid @RequestBody @Valid LoginRequest request, jakarta.servlet.http.HttpServletResponse response)
      Handles user login requests.
      Parameters:
      request - login credentials
      response - HTTP response to set cookie
      Returns:
      authentication response with tokens and user info
    • handleDeletionRequest

      @DeleteMapping("/delete-account") public MessageResponse handleDeletionRequest(@CookieValue("refreshToken") String refreshToken, jakarta.servlet.http.HttpServletResponse response)
      Handles user account deletion requests.
      Parameters:
      refreshToken - the refresh token identifying the user session
      response - HTTP response to clear cookies
      Returns:
      success message
    • handleLogoutRequest

      @PostMapping("/logout") public MessageResponse handleLogoutRequest(@CookieValue("refreshToken") String refreshToken, jakarta.servlet.http.HttpServletResponse response)
      Handles user logout requests, revoking the refresh token.
      Parameters:
      refreshToken - the refresh token to revoke
      response - HTTP response to clear cookies
      Returns:
      success message
    • handleHasSessionCookieRequest

      @GetMapping("/has-session") public boolean handleHasSessionCookieRequest(@CookieValue("refreshToken") String refreshToken)
      Checks if the user has an active session cookie.
      Parameters:
      refreshToken - the refresh token cookie
      Returns:
      true if the token is present
    • handleRefreshTokenRequest

      @PostMapping("/refresh-token") public AuthResponse handleRefreshTokenRequest(@CookieValue("refreshToken") String refreshToken, jakarta.servlet.http.HttpServletResponse response)
      Refreshes the access token using a valid refresh token.
      Parameters:
      refreshToken - the refresh token
      response - HTTP response to set new cookie
      Returns:
      authentication response with new tokens
    • handleGetCurrentUserRequest

      @GetMapping("/me") public UserResponse handleGetCurrentUserRequest()
      Returns details of the currently authenticated user.
      Returns:
      user info including ID, email, and name