Skip to content

Commit d16e00a

Browse files
committed
Release 0.1.8: surface toggles + middleware ordering in README
README now documents the ?__autologin__=tmp_off|logout|log_in toggles, the middleware ordering requirement for manual installs (after Session/Auth/Messages), and includes middleware_autoinstall and query_param in the configuration example. No code changes.
1 parent ad0b9af commit d16e00a

4 files changed

Lines changed: 65 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.8] — 2026-05-12
9+
10+
### Changed
11+
- README now documents the auth-state toggles
12+
(`?__autologin__=tmp_off|logout|log_in`) and the required middleware
13+
ordering for manual installs (after `SessionMiddleware`,
14+
`AuthenticationMiddleware`, and `MessageMiddleware`). The configuration
15+
example also includes the new `autologin.middleware_autoinstall` and
16+
`autologin.query_param` keys. No code changes.
17+
818
## [0.1.7] — 2026-05-12
919

1020
### Added

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Dev-time conveniences for Django projects: autologin endpoint, dotfiles for LLM
1010
## Features
1111

1212
- **Autologin endpoint** — one URL logs in a user via token, no interactive login needed
13+
- **Auth-state query toggles**`?__autologin__=tmp_off|logout|log_in` on *any* URL to flip auth state in the browser without leaving the page
1314
- **Dotfiles**`.dev_helpers_token`, `.dev_helpers_port`, `.dev_helpers_pg_*`, `.dev_helpers_redis_*` written to project root for easy `cat` by LLM agents
1415
- **Agent help prompt** — copy-pasteable curl/psql/redis-cli commands printed at startup
1516
- **Gitignore self-check** — warns if dotfiles are not in `.gitignore`
@@ -70,13 +71,58 @@ urlpatterns = [
7071

7172
## Usage
7273

73-
### Autologin
74+
### Autologin URL (token-based)
7475

7576
```bash
7677
T=$(cat .dev_helpers_token)
7778
curl -L "http://localhost:8000/__autologin__/?token=$T"
7879
```
7980

81+
### Auth-state toggles (browser-friendly)
82+
83+
Once `AutologinMiddleware` is wired (the default), every request is scanned for
84+
a toggle query parameter. Drop it onto any URL — the middleware handles it
85+
before URL resolution.
86+
87+
| URL on any view | Effect |
88+
|---|---|
89+
| `https://localhost:8000/some/page/?__autologin__=tmp_off` | Render **this one request** with `request.user = AnonymousUser`. Session unchanged — the next plain request is logged in again. Toggle param stripped from `request.GET` before the view sees it. |
90+
| `https://localhost:8000/some/page/?__autologin__=logout` | `django.contrib.auth.logout(request)` — ends the session. 302 to the same path with the toggle stripped; other query parameters preserved. |
91+
| `https://localhost:8000/some/page/?__autologin__=log_in` (or `login`) | Log in the configured user (`autologin.user_lookup_field` / `user_lookup_value`). 302 to the cleaned URL. No URL token required — the localhost host allowlist is the trust signal. |
92+
93+
Unknown values pass through silently (likely typos). Off-host requests pass
94+
through identically — the toggles do not announce their existence to
95+
unauthorized hosts.
96+
97+
Rename the parameter via `autologin.query_param`, or set it to `""` / `None`
98+
to disable the toggle layer while keeping the path-based `/__autologin__/`
99+
URL working. Full details and threat model:
100+
[docs/autologin.md](docs/autologin.md#toggle-query-parameters).
101+
102+
### Middleware ordering
103+
104+
`AutologinMiddleware` is auto-appended at the **end** of `settings.MIDDLEWARE`
105+
during `AppConfig.ready()`. That works because the toggles need
106+
`SessionMiddleware`, `AuthenticationMiddleware`, and `MessageMiddleware` to
107+
have already run by the time we look at the request — sessions for
108+
`logout`/`log_in`, `request.user` set up so `tmp_off` can override it, and
109+
`request._messages` for the path-based view's `flash_message`.
110+
111+
If you install the middleware **manually** (with
112+
`autologin.middleware_autoinstall=False`), place it **after** those three:
113+
114+
```python
115+
MIDDLEWARE = [
116+
"django.contrib.sessions.middleware.SessionMiddleware",
117+
"django.contrib.auth.middleware.AuthenticationMiddleware",
118+
"django.contrib.messages.middleware.MessageMiddleware",
119+
# ... your other middleware ...
120+
"django_dev_helpers.middleware.AutologinMiddleware",
121+
]
122+
```
123+
124+
Putting it before `SessionMiddleware`/`AuthenticationMiddleware`/`MessageMiddleware` will break `logout`, `log_in`, and `flash_message` respectively.
125+
80126
### Management Commands
81127

82128
```bash
@@ -117,6 +163,12 @@ DJANGO_DEV_HELPERS = {
117163
"user_lookup_value": "admin",
118164
"url_path": "__autologin__/",
119165
"redirect_to": "/",
166+
# Middleware that handles the autologin URL + auth-state toggles.
167+
# Auto-appended to settings.MIDDLEWARE; refuses to load when DEBUG=False.
168+
"middleware_autoinstall": True,
169+
# Name of the query toggle (?__autologin__=tmp_off|logout|log_in).
170+
# Set to "" or None to disable the toggle layer.
171+
"query_param": "__autologin__",
120172
},
121173
"dotfiles": {
122174
"enabled": True,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "django-dev-helpers"
7-
version = "0.1.7"
7+
version = "0.1.8"
88
description = "Dev-time conveniences for Django projects: autologin endpoint, dotfiles for LLM agents, gitignore self-check"
99
readme = "README.md"
1010
license = "MIT"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)