Skip to content

Commit 7e3f489

Browse files
committed
More variable naming consistency
1 parent 56c9b3d commit 7e3f489

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

src/reactpy_django/auth/components.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -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

src/reactpy_django/hooks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ async def login(user: AbstractUser, rerender: bool = True):
432432
await channels_auth.login(scope, user, backend=config.REACTPY_AUTH_BACKEND)
433433
session_save_method = getattr(scope["session"], "asave", scope["session"].save)
434434
await ensure_async(session_save_method)()
435-
await scope["reactpy"]["synchronize_session"]()
435+
await scope["reactpy"]["synchronize_auth"]()
436436

437437
if rerender:
438438
await scope["reactpy"]["rerender"]()

src/reactpy_django/http/urls.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
name="view_to_iframe",
1717
),
1818
path(
19-
"session/<uuid:uuid>",
20-
views.session_manager,
21-
name="session_manager",
19+
"auth/<uuid:uuid>",
20+
views.auth_manager,
21+
name="auth_manager",
2222
),
2323
]

src/reactpy_django/http/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async def view_to_iframe(request: HttpRequest, dotted_path: str) -> HttpResponse
4444
return response
4545

4646

47-
async def session_manager(request: HttpRequest, uuid: str) -> HttpResponse:
48-
"""Switches the client's active session to match ReactPy.
47+
async def auth_manager(request: HttpRequest, uuid: str) -> HttpResponse:
48+
"""Switches the client's active auth session to match ReactPy's session.
4949
5050
This view exists because ReactPy is rendered via WebSockets, and browsers do not
5151
allow active WebSocket connections to modify cookies. Django's authentication

src/reactpy_django/websocket/consumer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async def run_dispatcher(self):
144144
"""Runs the main loop that performs component rendering tasks."""
145145
# TODO: Figure out why exceptions raised in this method are not being printed to the console.
146146
from reactpy_django import models
147-
from reactpy_django.auth.components import root_manager, session_manager
147+
from reactpy_django.auth.components import auth_manager, root_manager
148148
from reactpy_django.config import (
149149
REACTPY_REGISTERED_COMPONENTS,
150150
REACTPY_SESSION_MAX_AGE,
@@ -214,7 +214,7 @@ async def run_dispatcher(self):
214214
await serve_layout(
215215
Layout( # type: ignore
216216
ConnectionContext(
217-
session_manager(),
217+
auth_manager(),
218218
root_manager(root_component),
219219
value=connection,
220220
)

0 commit comments

Comments
 (0)