Commit 4fca412
fix(supabase_flutter): preserve hash routes and repeated query keys when clearing auth params (#1511)
## What
`removeAuthParametersFromUrl` cleans the auth parameters out of a URL
after a code exchange. It had two bugs that broke URLs it was supposed
to leave intact:
1. **Hash-based routes were corrupted.** The fragment was parsed with
`Uri.splitQueryString` and re-emitted as query parameters, so a route
like `#/dashboard` became `#%2Fdashboard`. Hash-based routing is Flutter
web's **default** URL strategy, so after a PKCE callback the app route
was mangled.
2. **Repeated query keys were dropped.** It read `queryParameters` (last
value wins), so `?tag=a&tag=b` collapsed to `?tag=b`.
Both contradict the function's own docstring ("preserving any unrelated
parameters").
## Why
```dart
// (1) fragment treated as a query string, then re-encoded
Uri.splitQueryString(currentUri.fragment) // '/dashboard' -> {'/dashboard': ''}
// (2) last-wins map loses duplicates
Map<String, String>.of(currentUri.queryParameters) // ?tag=a&tag=b -> {tag: b}
```
Fix:
- Use `queryParametersAll` so repeated keys are preserved.
- Only rewrite the fragment when it actually contains an auth parameter
(implicit flow: `#access_token=...`); otherwise preserve it verbatim so
routes aren't touched.
## Not a breaking change
Auth clearing is unchanged: the PKCE `code` in the query and
implicit-flow tokens in the fragment are still removed. Only
previously-corrupted output changes — hash routes and duplicate query
keys are now preserved.
## Tests
Extends `clear_auth_url_parameters_test.dart` (all 6 existing tests
still pass):
- `#/dashboard` is preserved (was `#%2Fdashboard`).
- `?tag=a&tag=b&code=abc123` → `?tag=a&tag=b` (was `?tag=b`).
- Implicit-flow tokens in the fragment are still cleared.
The two new bug tests fail on the current code and pass with the fix.
`dart format` and `dart analyze --fatal-warnings` are clean.
---------
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>1 parent 682dd96 commit 4fca412
2 files changed
Lines changed: 59 additions & 10 deletions
File tree
- packages/supabase_flutter
- lib/src
- test
Lines changed: 18 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 31 | | |
40 | 32 | | |
41 | 33 | | |
42 | 34 | | |
43 | 35 | | |
44 | 36 | | |
45 | 37 | | |
46 | | - | |
| 38 | + | |
47 | 39 | | |
48 | 40 | | |
49 | 41 | | |
50 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
55 | 96 | | |
56 | 97 | | |
0 commit comments