Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): token login method session restoration #5497

Merged
merged 6 commits into from
Jan 18, 2024

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented Jan 12, 2024

Description

When initialising AuthStore, Studio only attempts to read the cookieless auth token from localStorage if the login method is dual. If the login method is token (e.g. cookie-based auth is explicitly disabled), Studio does not attempt to read the cookieless auth token from localStorage. This means that the active session is not restored when Studio initialises (e.g. when reloading the host webpage after signing in).

The fix is quite small. As part of this work, I've also taken care of a few small chores.

What to review

Configure a Studio workspace to authenticate using the token method:

{
  auth: {
    loginMethod: 'token',
   },
}

Sign into the Studio, and then reload the webpage. The active session should be restored (prior to this fix, the user is shown the sign-in UI at this point).

Note that when using the test-studio inside the Sanity monorepo, this issue only occurs in production builds. You can test the production build using the serve npm package (npm i -g serve):

cd dev/test-studio
yarn sanity:build
serve -s -l 3333 dist

Notes for release

Correctly restore the active session when the token login method is used.

Copy link

vercel bot commented Jan 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Jan 18, 2024 10:57am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 18, 2024 10:57am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jan 18, 2024 10:57am

@juice49 juice49 force-pushed the fix/sdx-868-token-hydration branch from 8666d69 to 2b2fa8a Compare January 12, 2024 12:41
@juice49 juice49 marked this pull request as ready for review January 12, 2024 12:51
@juice49 juice49 requested a review from a team as a code owner January 12, 2024 12:51
@juice49 juice49 requested review from rexxars and removed request for a team January 12, 2024 12:51
@juice49 juice49 force-pushed the fix/sdx-868-token-hydration branch from 2b2fa8a to aafa90e Compare January 12, 2024 12:52
@juice49 juice49 requested a review from a team January 12, 2024 12:53
@juice49 juice49 changed the title Fix/sdx 868 token hydration fix(core): token login method session restoration Jan 12, 2024
@juice49 juice49 force-pushed the fix/sdx-868-token-hydration branch from aafa90e to eea2c9c Compare January 12, 2024 13:01
Copy link
Contributor

github-actions bot commented Jan 12, 2024

Package Documentation Change
sanity -2%
Full Report
@sanity/diff
This branch Next branch
13 documented 13 documented
16 not documented 16 not documented
@sanity/block-tools
This branch Next branch
4 documented 4 documented
9 not documented 9 not documented
@sanity/types
This branch Next branch
55 documented 55 documented
234 not documented 234 not documented
sanity/desk
This branch Next branch
84 documented 84 documented
64 not documented 64 not documented
@sanity/portable-text-editor
This branch Next branch
21 documented 21 documented
44 not documented 44 not documented
@sanity/mutator
This branch Next branch
7 documented 7 documented
4 not documented 4 not documented
@sanity/cli
This branch Next branch
1 documented 1 documented
31 not documented 31 not documented
@sanity/schema/_internal
This branch Next branch
0 documented 0 documented
12 not documented 12 not documented
@sanity/util/paths
This branch Next branch
1 documented 1 documented
15 not documented 15 not documented
sanity/router
This branch Next branch
17 documented 17 documented
26 not documented 26 not documented
@sanity/util/legacyDateFormat
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/schema
This branch Next branch
0 documented 0 documented
2 not documented 2 not documented
sanity/structure
This branch Next branch
2 documented 2 documented
6 not documented 6 not documented
sanity/cli
This branch Next branch
2 documented 2 documented
0 not documented 0 not documented
@sanity/vision
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/util/fs
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
sanity/_internal
This branch Next branch
0 documented 0 documented
1 not documented 1 not documented
sanity/_internalBrowser
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/util/content
This branch Next branch
1 documented 1 documented
5 not documented 5 not documented
sanity
This branch Next branch
177 documented 181 documented
843 not documented 851 not documented

Copy link
Contributor

github-actions bot commented Jan 12, 2024

Component Testing Report Updated Jan 18, 2024 10:59 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 11s 3 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 13s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 33s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 18s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 0s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 6s 3 0 0

Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fix! Small request for a visibility change.

packages/sanity/src/core/config/auth/types.ts Outdated Show resolved Hide resolved
@juice49 juice49 added this pull request to the merge queue Jan 18, 2024
Merged via the queue into next with commit ae44bc7 Jan 18, 2024
40 checks passed
@juice49 juice49 deleted the fix/sdx-868-token-hydration branch January 18, 2024 11:02
juice49 added a commit that referenced this pull request Jan 18, 2024
* chore(core): fix typo

* feat(core): add login method types

* feat(core): add `isCookielessCompatibleLoginMethod` type guard

* fix(core): if any cookieless compatible login method is used, attempt to retrieve token from localStorage

* chore(core): move `isAuthStore` type guard to new `asserters` module

* refactor(core): adjust `CookielessCompatibleLoginMethod` type visibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants