title: How to get current logged in user in django with a custom abstract user
body: <p>I'm trying to get the user which is actively making a post request to my api. I am using this to associate a posting with the user that makes it. However, when I make a post, it always returns Anonymous User. I am able to authenticate, sign up, and login properly. Is there any other way I could go about this?</p>
  <p>I am using django allauth to authenticate with email</p>
  <p>I have the following User model:</p>
  <pre><code>class CustomUser(AbstractBaseUser, PermissionsMixin):
  email = models.EmailField(_('email address'), unique=True)
  password = models.CharField(max_length=78)
  full_name = models.CharField(max_length=50)
  is_staff = models.BooleanField(default=False)
  is_active = models.BooleanField(default=True)
  date_joined = models.DateTimeField(default=timezone.now)
  
  USERNAME_FIELD = 'email'
  REQUIRED_FIELDS = []
  
  objects = CustomUserManager()
  
  def __str__(self):
      return(self.email)
  </code></pre>
  <p>The following is my Listing model:</p>
  <pre><code>class Listing(models.Model):
  listingId = models.IntegerField(max_length=5)
  streetAddress = models.CharField(max_length=120)
  city = models.CharField(max_length=120)
  state = models.CharField(max_length=120)
  zipCode = models.IntegerField(max_length=5)
  price = models.IntegerField(max_length=6)
  deposit = models.IntegerField(max_length=6, default=0)
  description = models.TextField()
  rooms = models.IntegerField(max_length=2)
  bathrooms = models.IntegerField(max_length=2)
  rentalType = models.IntegerField(choices=RentalType.choices(), default=RentalType.HOUSE)
  amenities = models.TextField()
  listingUser = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='listings', on_delete=models.CASCADE, null=True)
  dateAvailable = models.DateTimeField(default=datetime.now)
  created = models.DateTimeField(auto_now_add=True)
  updated = models.DateTimeField(auto_now=True)
  
  def __str__(self):
      return self.streetAddress
  </code></pre>
  <p>And my views.py for the Listing model</p>
  <pre><code>class ListingViewSet(viewsets.ModelViewSet):
  queryset = Listing.objects.all()
  serializer_class = ListingSerializer
  
  def perform_create(self, serializer):
      custom = settings.AUTH_USER_MODEL
      user = get_user_model()
      print(self.request.user)
      #serializer.save(listingUser=self.request.user)
  
  def get(self, request, *args, **kwargs):
      return self.list(request, *args, *kwargs)
  
  def post(self, request, *args, **kwargs):
      return self.create(request, *args, **kwargs)
  </code></pre>
  <p>Edit: I am setting up django on a different server than my front-end. Not sure if that might make a difference to my current approach. I tried researching the request.user method. From what I understood, it accesses the default user model.</p>
  <p>Settings.py</p>
  <pre><code>AUTH_USER_MODEL = 'users.CustomUser'
  
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'django.contrib.sites',
      'corsheaders',
      'listing',
      'users',
      'rest_framework',
      'rest_framework.authtoken',
      'rest_auth',
      'allauth',
      'allauth.account',
      'rest_auth.registration',
      'allauth.socialaccount', 
  ]
  
  REST_AUTH_SERIALIZERS = {
      'USER_DETAILS_SERIALIZER': 'users.serializers.UserSerializer',
  }
  
  REST_AUTH_REGISTER_SERIALIZERS = {
          'REGISTER_SERIALIZER': 'users.serializers.UserSerializer',
      }
  
  
  AUTHENTICATION_BACKENDS = (
     &quot;allauth.account.auth_backends.AuthenticationBackend&quot;,
  )
  
  ACCOUNT_USER_MODEL_USERNAME_FIELD = None
  ACCOUNT_EMAIL_REQUIRED = True
  ACCOUNT_USERNAME_REQUIRED = False
  ACCOUNT_AUTHENTICATION_METHOD = 'email'
  ACCOUNT_EMAIL_VERIFICATION = 'none'
  ACCOUNT_UNIQUE_EMAIL = True 
  </code></pre>