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

@tinacms/cli update to v1.5.34 caused auth/authHooks onLogout don't triggered #4356

Closed
3 tasks done
mddanish00 opened this issue Nov 21, 2023 · 4 comments · Fixed by #4377 or #4372
Closed
3 tasks done

@tinacms/cli update to v1.5.34 caused auth/authHooks onLogout don't triggered #4356

mddanish00 opened this issue Nov 21, 2023 · 4 comments · Fixed by #4377 or #4372
Labels
bug Something isn't working

Comments

@mddanish00
Copy link

Describe the issue that you're seeing. Any Loom videos or screenshots usually help a lot!

I used onLogin and onLogout hooks for draft/preview mode. I noticed that draft mode isn't disabled when I try to log out on TinaCMS admin. (in local)

I tested many things onLogout to conclude onLogout don't trigger after updating @tinacms/cli to v1.5.34.

If I downgrade the @tinacms/cli package to v1.5.31, it works normally again.

Reproduction

https://github.com/mddanish00/tina-new-ver-save-authhooks

Steps to reproduce

  1. Install all dependencies using yarn.
  2. Run npm run dev.
  3. Go to TinaCMS admin.
  4. Try to log out. The supposed thing to happen here is the page will be redirected to a page named api/logout that doesn't exist. (I don't know a better way to test this.)
  5. Click 'Enable Edit Mode'. You can see in the browser console that onLogin worked properly
  6. Stop the dev server.
  7. Try downgrading @tinacms/cli to v1.5.31
  8. Change authHooks into auth in tina/config.js
  9. Run npm run dev again.
  10. Try again to Logout and Login.

System Info

System:
    OS: Linux 6.5 Ubuntu 23.10 23.10 (Mantic Minotaur)
    CPU: (4) x64 Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz
    Memory: 10.49 GB / 15.53 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.9.0 - /tmp/xfs-502d4bc4/node
    Yarn: 4.0.2 - /tmp/xfs-502d4bc4/yarn
    npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
  Browsers:
    Chrome: 119.0.6045.159
  npmPackages:
    @tinacms/cli: 1.5.34 => 1.5.34 
    tinacms: 1.5.24 => 1.5.24

Validations

@mddanish00 mddanish00 added the bug Something isn't working label Nov 21, 2023
@logan-anderson
Copy link
Contributor

@mddanish00 Thanks for reporting this issue.

The function is being called but for some reason window.location.href = '/api/preview' is not working.

As a temporary work around you can add await new Promise((resolve) => setTimeout(resolve, 1000)) to the end of onLogout and it will work as expected.

See video for more details:https://www.loom.com/share/aef59a816ca1472fa9c03ba47b0893b8

I am looking into a fix that works as expected (same as the previous versions)

@logan-anderson
Copy link
Contributor

@mddanish00 Does using window.history.pushState({}, '', myUrl) instead of window.location.href = myUrl work as desired?

If it does work as intended, we may update the docs / examples to use this pattern instead.

@mddanish00
Copy link
Author

I quickly tried this by updating my preview mode code but it didn't really work as I expected like before. It feels like the address just changed, browser don't actually go there.

I tried both onLogin and onLogout. Preview mode don't activate at all. Also, it also do not redirect to the address that specified on the slug parameter.

@logan-anderson
Copy link
Contributor

I quickly tried this by updating my preview mode code but it didn't really work as I expected like before. It feels like the address just changed, browser don't actually go there.

I tried both onLogin and onLogout. Preview mode don't activate at all. Also, it also do not redirect to the address that specified on the slug parameter.

Gotcha! Thanks for trying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants