display data in real time and filter on the user (websocket)

I gave up on vue a couple years ago - I’m not sure I can follow the sequence of what’s happening here.

Are you logging in before the websocket is being opened?

I can’t follow that in the code - I don’t know vue well enough for that.

You should be able to check this in your server log. If you see the GET for the websocket before the POST for your login, then that’s bad. If you’ve got the POST for your login before the GET for the websocket, then the issue is somewhere else.

i have this
(overlay its my page)

System check identified 1 issue (0 silenced).
November 02, 2022 - 19:47:25
Django version 4.0.5, using settings 'OrderLine1.settings'
Starting ASGI/Channels version 3.0.1 development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
HTTP GET /myapp/overlay 200 [0.01, 127.0.0.1:61544]
WebSocket HANDSHAKING /ws/ [127.0.0.1:61547]
WebSocket CONNECT /ws/ [127.0.0.1:61547]
AnonymousUser

So no, you’re not logged in at the time the websocket connection is established.

Therefore you do not have a User associated with your session and the scope wouldn’t have a User object associated with it.

what should I do in this case the

The easiest way to work around this would be to create your login page allowing you to log in and have the login page redirect you to this page after a successful login.

(There are other options, but this is the easiest to ensure that you are logged in to the site when the websocket is opened.)

I changed the redirection url on overlay but it did not change anything I still have AnonymousUser

Again, observe your log - what is the sequence of the requests being submitted to the server?

System check identified 1 issue (0 silenced).
November 02, 2022 - 20:05:45
Django version 4.0.5, using settings 'OrderLine1.settings'
Starting ASGI/Channels version 3.0.1 development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
HTTP POST /myapp/index 302 [0.30, 127.0.0.1:61921]
HTTP GET /myapp/overlay 200 [0.01, 127.0.0.1:61921]
WebSocket HANDSHAKING /ws/ [127.0.0.1:61924]
WebSocket CONNECT /ws/ [127.0.0.1:61924]
AnonymousUser

And /myapp/index is your Django login page?

Yes its my login page

What session middleware are you using in Django, and what middleware do you have specified in your settings.py file?

this

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django_htmx.middleware.HtmxMiddleware',
    'corsheaders.middleware.CorsMiddleware',
]

The next thing to check then would be to verify that your websocket connection request includes the session cookie in what’s being sent to the server.

The easiest way I know of to do that is from your browsers network tab in the development tools to look at the details of the websocket messages being sent.

You might even want to go so far as to verify that your initial response after the login contains the session cookie.

this is not sensitive data I can show you?

I’m so stupid , I’m on the ngrok server

@KenWhitesell Thank you very much for everything