NilCoalescing / djangochannelsrestframework

A Rest-framework for websockets using Django channels-v4

Home Page:https://djangochannelsrestframework.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get user from view returns AnonymousUser

juliGer opened this issue · comments

Hello! I would like to get the user from the view but I can't find a way to do it, since I don't have the IsAuthenticated of django rest the request.user comes as Anonymous, the user I have in the scope since I added it through a middelware
So the question is can I get the user from the view? And if this is how it is done since I was reading the documentation and looking at the files but I can't find something that does this

This is a good point, the authenticated user is not currently injected into the request object when calling views through view_as_consumer

And to do it is very difficult? Because I was looking at the consumers.py file and in the call_view function it generates a request and then calls view(request...)

response = view(request, *args, **view_kwargs)

I try to add doing request.user = self.scope['user'] and I add it correctly but in the view it keeps coming as anonymous. I don't know how line 273 works but apparently the request is not being passed or django is stepping on it

It wasn't working because I had something wrong in the settings. It's just adding request.user = self.scope['user'] in the call_view function after the request.session. Can I do a pull request to add this?

Line 253
image

Yer if you could open a PR with this that would epic.