Commit a936104
committed
Don't try to validate an invalidate token multiple times
I noticed that if a token is invalid because it has expired, we might call `from_token` multiple times. This is because `@current_user` is set to `nil` so won't be cached.
`from_token` calls `HydraPublicApiClient.fetch_oauth_user` which does an API request. Since we might call current_user many times in a controller, we shouldn't be doing a API request from each one.
Since we're currently recording unauthorized errors in Sentry, this often resulted in 3-5 errors being recorded for the same request.
Instead, load the current user once. This might mean in some API calls we're loading the user when we don't need to, but since almost all API actions should validate the current user I don't see this as a problem.
The identifible by cookie file doesn't have this problem, but I've updated it for consistency.1 parent 9d9d042 commit a936104
2 files changed
Lines changed: 12 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
0 commit comments