RESOLVE 500 ERROR在Springboot登录页面中

即使使用正确的凭据也显示出错误...注册页面正常工作... @postmapping(“/authenticate”) 公共响应> createAuthenticationToken(@requestbody AuthenticationRequest authenticationRequest)抛出异常{ 尝试 { authenticationmanager.authenticate(新的用户名passwordauthenticationtoken( AuthenticationRequest.getUsername(),AuthenticationRequest.getPassword() ); } catch(BadCredentialSexception e){ 返回响应态度。Status(httpstatus.unauthorized).body(null); }

    final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
    final String jwt = jwtUtil.generateToken(userDetails.getUsername());
    User user = userRepository.findFirstByEmail(authenticationRequest.getUsername());

    Map<String, Object> responseBody = new HashMap<>();
    responseBody.put("userId", user.getId());
    responseBody.put("role", user.getRole());

    return ResponseEntity.ok()
            .header(HEADER_STRING, TOKEN_PREFIX + jwt)
            .body(responseBody);
}

我试图交叉检查所有方法,似乎还不错

0 个回答

  • 5 浏览
  • Athira Pillai 提出于 2024-04-21 05:58:47

相似问题