Angular 5 Login and Logout with Web API Using Token Based Authentication - CodAffection
[the_ad_placement id="before-content"]

30 thoughts on “Angular 5 Login and Logout with Web API Using Token Based Authentication”

  1. HELLO HOW TO MAKE A LOGIN? with web API of an existing database with users table (id, name, first name, pwd, role); Thank you for your tutorials

  2. The video is excellent. I learned a lot. It is so much easy than the other web applications (I don’t want to name them… it may offense some people). I do have question to the author if he plan to release any videos soon for Angular and Microsoft API (MVC) with Identity user. Basically, Microsott with pre-package (login, register, logout…) but it is written in RCL (Razors Code Library).. It is good if you stay in Microsoft platform. However, I have added JWT token to the login.cshtml.cs (the code generated in the area/identity/account…). and it is not working at all. On the angular side, the localstorage.getItem(‘token’) always return null.

    I wonder any one can give me clues to fix the problem. It would be nice if there is a piece of code that write token to client computer.

    To me, it is the WRITETOKEN(token) is the problem child.

    Thank you.

  3. Angular 5 – Registration, Login and Logout with Web API using Token Based Authentication is Nice Tutorials and it’s work good.
    Thank u for these tutorials.

    i’m trying to develop for My Collage Project(Hybrid app in Ionic 4) can u help me in Update User Data, Show All Data and Change Password for these (Angular 5 – Registration, Login and Logout with Web API using Token Based Authentication).

  4. var userStore = new UserStore(new ApplicationDbContext());
    var manager = new UserManager(userStore);
    var user = await manager.FindAsync(context.UserName, context.Password);
    if (user != null){
    ///code
    }

    Here user is showing null.
    manager.FindAsync —-in manager there is no any FindAsync method or property

    Could anyone please help me on this to figure out the issue?

  5. Peder Olofsson

    Just discovered that the action method for “token” is missing in your code example for the web api controller.

  6. I think that the original userAuthentication method used here can rise problems with passwords containing special characters, like “&” and so, because they are sent as url parameters. I think they should be encoded, using something like this:

    userAuthentication(userName, password) {
    let params = new HttpParams();
    params = params.append(“username”,userName);
    params = params.append(“password”,password);
    params = params.append(“grant_type”,’password’);
    var data = params.toString();
    var reqHeader = new HttpHeaders({ ‘Content-Type’: ‘application/x-www-urlencoded’,’No-Auth’:’True’ });
    return this.http.post(this.rootUrl + ‘/token’, data, { headers: reqHeader });
    }

    Hope this helps.

  7. BONJOUR COMMENT FAIRE UN LOGIN ? avec webapi d’une base de donnée existance avec table users( id,nom,prenom,pwd, role); Merci pour vos tutos

  8. Hi
    I have a problem,
    for auth.interceptor.ts : my VSCode has a problem that is:
    Property ‘do’ does not exist on type ‘Observable<HttpEvent>
    what am I dong to fix it?

  9. while login i m unable display the user claims in home page and while loading the page it shows this error and in web api action method getuserclaims it unable to hit.
    TypeError: You provided ‘undefined’ where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

    1. IONESCU VIRGILIU

      There is a bug. If the user does not have a token, the function navigates to ‘login/’, but does not return anything. You probabily use the return to subscribe.
      I’ve added a next call like so.

      else {
      this.router.navigateByUrl(‘/login’);
      return next.handle(req.clone());
      }

      Keep in mind that this is not to replace actual token check on the server, it just to add the headers in a single place

  10. Great job. Thanks for sharing. I am a dot net developer too but unlike you, I am just a beginner and also trying to share all my experience as a beginner. Can I make this post as a reference on my blog? Send me some emails if it’s ok.

  11. Hi, Сan you to show me your db struct? Which fill have in tour tables?
    I have error in my project,

  12. Hi,

    The tutorial details with video is really outstanding. Thanks for putting in all the efforts.

    It would be really great if you migrate current web API project to Asp.Net Core 2.o and provide all authentication/authorization methods by following Asp.Net Core 2.0 standards. Also use JWT Token option instead of basic token based option currently used as it seems JWT Token based authentication/authorization is getting more popular now a days

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
4 Shares
Share via
Copy link
Powered by Social Snap