Auth Service - Login
Let's create an authentication service for login functionality.
We'll cover the following...
At the moment, our signup service returns a user object. In our SignupComponent
, we’re logging that result to the console with a comment stating that we’ll eventually redirect the user to a dashboard, which we’ll create in the next chapter. By redirecting users to a dashboard when they signup, we’re effectively logging in a user on their behalf in addition to creating their account. So before we progress to the dashboard, we’ll need to create one more method, login
, in our AuthService
(returning users who’ve already created an account will have a separate login section we’ll be creating later).
If you return back to the API documentation section, you should see a section labeled “Sessions”. This is the endpoint we’ll need to hit to log in a user.
Within this section, we can see that, once again, we’ll need to submit a POST
request. This time the endpoint is /api/sessions
.
The request body for this route looks almost identical to the one for creating new users.
{
"username": "myUser",
"password": "password"
}
The only ...