admin管理员组文章数量:1291007
I have this error:
loginponent.ts:27 ERROR
- HttpErrorResponse {headers: _HttpHeaders, status: 200, statusText: 'OK', url: 'http://localhost:4200/authenticate', ok: false, …}
Zone - XMLHttpRequest.addEventListener:[email protected]:27LoginComponent_Template_button_click_12_listener@loginponent.html:14Zone - HTMLButtonElement.addEventListener:[email protected]:14Zone - HTMLButtonElement.addEventListener:[email protected]:2Promise.then(anonymous)
I understood that it is because I return an html format instead of json for a login page.
i have this in angular:
constructor(private http: HttpClient) { }
// Metodă pentru autentificare
login(credentials: { email: string; parola: string }) {
return this.http.post('/authenticate', credentials, { withCredentials: true });
}
}
in intellij i have 3 classes about login: SecurityConfig,CustomUserDetails and Custom UserDetaillsService.
in usercontroller i have:
@GetMapping("/authenticate")
public ResponseEntity<String> authenticate() {
return ResponseEntity.ok("Autentificare reușită!");
}
in userDetailsService i have:
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByEmail(username)
.orElseThrow(() -> new UsernameNotFoundException("User or password not found"));
return new CustomUserDetails(user.getEmail(),
user.getParola(),
authorities(),
user.getPrenume(),
user.getNume(),
user.getSex(),
user.getData_nasterii(),
user.getNumar_telefon(),
user.getTara());
}
public Collection<? extends GrantedAuthority> authorities() {
return Arrays.asList(new SimpleGrantedAuthority("USER"));
}
i put the code i think is important.
I want to make the login work. It's my first project and I have a lot of trouble, but this put me down.
本文标签: javahtml response instead jsonStack Overflow
版权声明:本文标题:java - html response instead json - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505795a2382313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论