Creating Token Service
In this lesson, we're going to create token service
Creating token service#
Now that we know what we need to return to the user, let's create a token service in our project. Inside the Infrastructure project, we can create a new folder called Services, and we need a new class called TokenService which will be responsible for generating a new token. Since we are creating a new class, let's create a UserDto class which we will return to the user. Inside API and Dto, we can create UserDto which will have the email of type string and token of type string. Coming back to the TokenService class, we need to create a constructor where we'll inject the UserManager of type User with the same name, userManagaer. Let's import both of them.
With user manager, we also need access to the Configuration files. I'll tell you why we need it in a minute, but for now, let's simply inject it with IConfiguration with name config. Let's import it from Microsoft Extensions Configuration. Now let's initialize fields from parameter for both of them.
API/Dto/UserDto.cs
namespace API.Dto
{
public class UserDto
{
public string Email { get; set; }
public string Token { get; set; }
}
}
This page is a preview of The newline Guide to Fullstack ASP.NET Core and React