title: How do I access user in Django Async view?
body: <p>I'm trying to access user but getting an error when the view is <code>async</code>.</p>
  <p>Code:</p>
  <pre class="lang-py prettyprint-override"><code>from django.http import JsonResponse
  
  
  async def archive(request):
      user = request.user
      return JsonResponse({'msg': 'success'})
  
  </code></pre>
  <p>error message:</p>
  <pre class="lang-sh prettyprint-override"><code>django.myproject.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
  </code></pre>
  <p>What I tried:</p>
  <pre class="lang-py prettyprint-override"><code>from django.http import JsonResponse
  from asgiref.sync import sync_to_async
  
  
  async def archive(request):
      # user = sync_to_async(request.user)
      # user = sync_to_async(request.user)()
      # user = await sync_to_async(request.user)
      user = await sync_to_async(request.user)()
      return JsonResponse({'msg': 'success'})
  </code></pre>
  <p>Still getting the same error.</p>
  <p>I want to access the user to check he/she has permission to archive a file.</p>
  <p>EDIT:
  I eventually figured out that I had to move it into a temporary method and run that as <code>sync_to_async</code>. I did this below:</p>
  <pre class="lang-py prettyprint-override"><code>def _check_user(request):
      user = request.user
      ''' Logic here '''
      return
  
  async def archive(request):
      await sync_to_async(_check_user, thread_sensitive=True)(request=request)
      ''' Logic here '''
  
  </code></pre>
  <p>And this seems to work, But not sure if this is the correct way of doing it?</p>