Commit 17266ab
fix(ui):
Fixes #15926.
### What?
In the `AuthContext`, which can be consumed via the `useAuth` hook
imported from `@payloadcms/ui`, there is a `token` property which gets
set in the internal function `setFullUser`. This function assumes that
the `userResponse` argument passed to it always has the token on the
property `.token`, when in fact it exists on the property
`.refreshedToken` when the function is invoked after the auth cookie has
been refreshed. Because of this `useAuth().token` is often nullish when
it shouldn't be.
### Why?
I want to be able to rely on the `useAuth` hook. Now I can't (or at
least not on the `token` property), because there's a bug related to it.
### How?
I changed the type for the `userResponse` parameter (`UserWithToken`) to
convey that sometimes it's `.token` and sometimes it's
`.refreshedToken`. Then I set the `token` property (the `tokenInMemory`
state) to either `userResponse.token` or `userResponse.refreshedToken`
depending on which property exists on the object (`userResponse`).
<!--
Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.
Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.
The following items will ensure that your PR is handled as smoothly as
possible:
- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change
### What?
### Why?
### How?
Fixes #
-->
---------
Co-authored-by: German Jablonski <GermanJablo@users.noreply.github.com>tokenInMemory not set after refreshing cookie (#15928)1 parent 80ae745 commit 17266ab
3 files changed
Lines changed: 32 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
158 | | - | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
33 | 46 | | |
34 | 47 | | |
35 | 48 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
314 | 329 | | |
315 | 330 | | |
316 | 331 | | |
| |||
0 commit comments