@@ -37,9 +37,9 @@ async def rerender():
3737
3838
3939@component
40- def session_manager ():
41- """This component can force the client (browser) to switch HTTP sessions,
42- making it match the websocket session, by using a authentication token .
40+ def auth_manager ():
41+ """This component uses a client-side component alongside an authentication token
42+ to make the client (browser) to switch the HTTP auth session, to make it match the websocket session .
4343
4444 Used to force persistent authentication between Django's websocket and HTTP stack."""
4545 from reactpy_django import config
@@ -52,24 +52,24 @@ def session_manager():
5252 def setup_asgi_scope ():
5353 """Store trigger functions in the websocket scope so that ReactPy-Django's hooks can command
5454 any relevant actions."""
55- scope ["reactpy" ]["synchronize_session " ] = synchronize_session
55+ scope ["reactpy" ]["synchronize_auth " ] = synchronize_auth
5656
5757 @hooks .use_effect (dependencies = [synchronize_requested ])
58- async def synchronize_session_watchdog ():
59- """Detected if the client has taken too long to request a session synchronization.
58+ async def synchronize_auth_watchdog ():
59+ """Detected if the client has taken too long to request a auth session synchronization.
6060
6161 This effect will automatically be cancelled if the session is successfully
62- switched (via effect dependencies)."""
62+ synchronized (via effect dependencies)."""
6363 if synchronize_requested :
6464 await asyncio .sleep (config .REACTPY_AUTH_TOKEN_TIMEOUT + 0.1 )
6565 await asyncio .to_thread (
6666 _logger .warning ,
67- f"Client did not switch sessions within { config .REACTPY_AUTH_TOKEN_TIMEOUT } (REACTPY_AUTH_TOKEN_TIMEOUT) seconds." ,
67+ f"Client did not switch authentication sessions within { config .REACTPY_AUTH_TOKEN_TIMEOUT } (REACTPY_AUTH_TOKEN_TIMEOUT) seconds." ,
6868 )
6969 set_synchronize_requested (False )
7070
71- async def synchronize_session ():
72- """Event that can command the client to switch HTTP sessions (to match the websocket session)."""
71+ async def synchronize_auth ():
72+ """Event that can command the client to switch HTTP auth sessions (to match the websocket session)."""
7373 session : SessionBase | None = scope .get ("session" )
7474 if not session or not session .session_key :
7575 return
@@ -85,30 +85,31 @@ async def synchronize_session():
8585 # Create a fresh token
8686 token .set_current (str (uuid4 ()))
8787
88- # Begin the process of synchronizing HTTP and websocket sessions
88+ # Begin the process of synchronizing HTTP and websocket auth sessions
8989 obj = await AuthToken .objects .acreate (value = token .current , session_key = session .session_key )
9090 await obj .asave ()
9191 set_synchronize_requested (True )
9292
93- async def synchronize_session_callback (status_code : int , response : str ):
93+ async def synchronize_auth_callback (status_code : int , response : str ):
9494 """This callback acts as a communication bridge, allowing the client to notify the server
95- of the status of session switch."""
95+ of the status of auth session switch."""
9696 set_synchronize_requested (False )
9797 if status_code >= 300 or status_code < 200 :
9898 await asyncio .to_thread (
99- _logger .warning ,
100- f"Client returned unexpected HTTP status code ({ status_code } ) while trying to sychronize sessions." ,
99+ _logger .error ,
100+ f"Client returned unexpected HTTP status code ({ status_code } ) while trying to synchronize authentication sessions." ,
101101 )
102102
103- # If needed, synchronize sessions by configuring all relevant session cookies.
104- # This is achieved by commanding the client to perform a HTTP request to our session manager endpoint.
103+ # If needed, synchronize authenication sessions by configuring all relevant session cookies.
104+ # This is achieved by commanding the client to perform a HTTP request to our session manager endpoint,
105+ # which will set any required cookies.
105106 if synchronize_requested :
106107 return HttpRequest (
107108 {
108109 "method" : "GET" ,
109- "url" : reverse ("reactpy:session_manager " , args = [token .current ]),
110+ "url" : reverse ("reactpy:auth_manager " , args = [token .current ]),
110111 "body" : None ,
111- "callback" : synchronize_session_callback ,
112+ "callback" : synchronize_auth_callback ,
112113 },
113114 )
114115
0 commit comments