BACK_END
Code: Select all
@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.cors(Customizer.withDefaults())
.authorizeHttpRequests((requests) -> {
requests.requestMatchers("/roles/**").permitAll();
requests.requestMatchers("/auth/**").permitAll();
requests.requestMatchers("/jobs/**").hasAnyRole("APPLICANT");
requests.requestMatchers("/applications/**").permitAll();
requests.requestMatchers("/users/**").hasAnyRole("APPLICANT");
requests.anyRequest().authenticated();
});
http.formLogin(Customizer.withDefaults());
http.httpBasic(Customizer.withDefaults());
http.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
http.exceptionHandling(exception->exception.authenticationEntryPoint(jwtAuthEntry));
return http.build();
}
Code: Select all
@GetMapping("profile")
public ResponseEntity getProfile(){
User userDto=userService.profile();
return ResponseEntity.ok(userDto);
}
Code: Select all
const API_BASE_URL='http://localhost:8080/users';
export const getUserProfile=(token)=>fetch(API_BASE_URL+'/profile',{
method:'GET',
headers:{
'Authorizations':token
}
}).then(res=>res.text()).catch(error=>console.error(error))
Code: Select all
const getProfile=()=>{
const token=localStorage.getItem('token')
console.log(token)
getUserProfile().then(res=>{
setUsers(res)
console.log(res.token)
console.log(res.token)
})
}
Gibt es ein Problem mit meinem Code? Oder gibt es einen einfacheren Weg, dies zu tun?
Mobile version