Search code examples
djangodjango-channels

Django Channels Login Page


I have a site that uses Django and Vue, hosted in Docker containers, along with other containers like Celery, Redis, Nginx, Postgress etc. I'd like to use Django Channels but cant seem to figure out how a login page is meant to work.

I'm not sure if I can do a whole website with Channels exclusively or must I use something like django.contrib.auth or Django REST framework together with Channels, I tried implamenting Django REST framework but got CORS errors.

According to the Channels Autentication Docs there are login and logout methods, but they sit in the receive() Channels consumer, what am I meant to do with the connect() method? Am I meant to accept the websocket connection before authenticating?

Or am I meant to use another meathod of authenticating my login page?

I just need a bit of guidance, your help would be much appreciated.


Solution

  • you have two options with middlewares, first is to write middleware and put some data in the header like username and password or something else and authenticate that, the second option is to write an API to give username and password and generate an access token to put in the header and authenticate the token in middleware, The last option is more secure