GET http://localhost:4200/api/user/ 404 (Not Found) angular 2

1.4k Views Asked by At

I have this error when I try to login to my app but i have some problems with a 404(not found) included... I will put some lines of my code and the image of the error..... Please help me fix the issue .

@Injectable()
export class AuthGuard implements CanActivateChild {
  loggedInUser: string;

  constructor( private localStorage: LocalStorageService, private router: Router ) {
    this.loggedInUser = localStorage.get('discogs-user') as string;
  }

  canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    if (this.loggedInUser) {
      return true;
    }

    this.router.navigate(['/login']);
  }
}

this is the login.component.ts with the subscribe

import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { Router } from '@angular/router';

import { Observable } from 'rxjs/Observable';

import { MdlSnackbarService } from 'angular2-mdl';

import * as fromRoot from '../../reducers';
import * as user from '../../actions/user';

import { DiscogsUser, UserLogin } from '../../models';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html'
})
export class LoginComponent {
  user$: Observable<DiscogsUser>;

  login(login: UserLogin) {
    if (!login.username) {
      this.store.dispatch(new user.LoginFailedAction('You must enter a username'));
      return;
    }

    this.store.dispatch(new user.LoginAction(login));
    this.router.navigate(['/']);
  }

  private _showError(message: string) {
    this.mdlSnackbarService.showSnackbar({
      message: message,
      action: {
        handler: () => { },
        text: 'OK'
      }
    });
  }

  constructor(private store: Store<fromRoot.State>, private router: Router, private mdlSnackbarService: MdlSnackbarService) {
      this.user$ = store.select(fromRoot.getUser);

      store.select(fromRoot.getLoginFailed)
        .subscribe(error => {
          if (error) {
            this._showError(error);
          }
        });

    }
}

this is the image of the error

error

0

There are 0 best solutions below