Logging in using restAPIfails in browser , but works in postman.
here is my angular code for login, which throws me 401
login(username: string, password: string) {
const httpHeaders = new HttpHeaders()
.set('Accept', 'application/json')
.set('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post<any>(environment.apiUrl + '/api/core/login',
JSON.stringify({ 'username': username, 'password': password }), {withCredentials: true, headers: httpHeaders})
.pipe(map(response => {
// login successful if there's a jwt token in the response
const token = response.headers.get('Lemon-Authorization');
if (response.status === 200 && token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('authHeader', 'Bearer ' + token);
this.currentUserSubject.next(response.body.user);
}
return response.body.user;
}));
}
401 in chrome: faliure in chrome
200 OK in postman : success in postman
what am i missing?