Commit 14f3b76
authored
Don't use cached user if session has been reset (#79)
This is a bit of an edge case, but if the user is logged in and then the
session is reset (or at least its `current_user` value is reset) and
`RpiAuth::Controllers::CurrentUser#current_user` is called within the
*same* request, then previously it would have returned the user "cached"
in the `@current_user`. Now it will return `nil` which seems less
surprising.
This was highlighted by [this example][1] in code-club-frontend. In that
case the example passes, because that app has [its own implementation of
`#current_user`][2]. However, when I added a similar example in
experience-cs where we're using
`RpiAuth::Controllers::CurrentUser#current_user`, the example failed.
I've added a rather contrived example by adding a new
`HomeController#reset_user` action to the dummy app used in the specs.
However, hopefully it helps explain a bit about why the change is
necessary.
It looks as if the only two RPF repos that use
`RpiAuth::Controllers::CurrentUser` are experience-ai [here][3] and
[here][4] and [experience-cs][5]. I'm pretty confident this change won't
affect either of those apps, so this can probably be a minor version
bump.
I think a possible alternative to making this change would be to provide
a `#reset_user` method which could both reset the session *and* reset
the ivar-cached user. However, given that the code-club-frontend
implementation already uses this approach, I think that probably makes
more sense for now.
[1]:
https://github.com/RaspberryPiFoundation/code-club-frontend/blob/901f2200e926741fd170858286d64f1dd49994b4/spec/requests/refresh_credentials_spec.rb#L90
[2]:
https://github.com/RaspberryPiFoundation/code-club-frontend/blob/901f2200e926741fd170858286d64f1dd49994b4/app/controllers/concerns/authentication_concern.rb#L6-L11
[3]:
https://github.com/RaspberryPiFoundation/experience-ai/blob/ad729cefe060fcc0f0c345b3297247069fe55867/app/controllers/application_controller.rb#L6
[4]:
https://github.com/RaspberryPiFoundation/experience-ai/blob/ad729cefe060fcc0f0c345b3297247069fe55867/app/controllers/api/v1/zipped_resources_controller.rb#L6
[5]:
https://github.com/RaspberryPiFoundation/experience-cs/blob/33fa4756371fa3a550f32ac7613130e0925c17d3/app/controllers/application_controller.rb#L4File tree
4 files changed
+17
-1
lines changed- lib/rpi_auth/controllers
- spec/dummy
- app/controllers
- config
- spec/requests
4 files changed
+17
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
4 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
185 | 194 | | |
186 | 195 | | |
187 | 196 | | |
| |||
0 commit comments