From the course: Building Angular and ASP.NET Web API Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Authentication check via tokens

Authentication check via tokens

From the course: Building Angular and ASP.NET Web API Apps

Start my 1-month free trial

Authentication check via tokens

- [Instructor] Now that we get the token package from our Web API, let us store the values in our local storage so then we can check if a user is authenticated or not. For that, let us go to our Angular project. In your register.component.ts file, go to the onSubmit method and inside here, you're going to use the response that we get from the data to store in our local storage. So let us change the data type to be any, and then in here, write localStorage.setItem. So we're going to set an item in our local storage and the key to this item is going to be username and the value is going to be data.username. Let us do the same for the token value so for that, we just write in here instead of username, token value and then instead of username, we are going to use token. Let us go to our Angular application and see the result. Go to register, in here, enter some data so etrupja. Then a password, and then I will confirm the password. Before I send the request, let me open the console window…

Contents