Login Serializer

Learn how to create a serializer for logging in users.

We'll cover the following

There are three steps for logging in a user using Simple JWT:

  1. Implementing the serializer
  2. Implementing the view
  3. Implementing the endpoint

This lesson focuses on implementing the serializer.

Building the login serializer

The login serializer ships and validates all the necessary data to log in a user. This means it takes the email and password submitted by a user during login, validates them, and then serializes them. During the validation stage, we can customize it to raise custom exceptions in the case of some errors. This serializer returns the user’s email and token if the user submits the correct credentials. The ModelSerializer helps us map some fields from the User model. Let’s add it in serializers.py.

Get hands-on with 1200+ tech skills courses.