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

User not staying logged in after page refresh #117

Open
maxsteinwand opened this issue Aug 29, 2024 · 6 comments
Open

User not staying logged in after page refresh #117

maxsteinwand opened this issue Aug 29, 2024 · 6 comments

Comments

@maxsteinwand
Copy link

Right now if the user logs in all the requests via the SDK are working as your authenticated but if you press F5 the user gets thrown back to the login even if the refresh_token cookie is set. You can try this on your own domain https://www.agencyos.dev/ (even tough you need to set the domain in directus to www.agencyos.dev as it currently cant set the cookie). Before you used a custom CookieStorage with type JSON when authenticating with the SDK but now with mode Cookie it still doesnt work.

Do you have any idea on how to fix this?

@tempo22
Copy link

tempo22 commented Aug 30, 2024

I have the same issue on self hosted env. I believe it has something to do with the change from session to cookie based auth

@omgitsjan
Copy link
Contributor

Same issue on my side as well

@karndt84
Copy link

No fix at the moment. So the whole thing is pretty useless

@samhallam16021
Copy link

Has anyone had any luck on this? I have the same issue.

@maxsteinwand
Copy link
Author

@tempo22 @karndt84 @samhallam16021
I have just readded the CookieStorage in the modules/directus/runtime/plugins/directus.ts file.

  class CookieStorage {
    get() {
      const cookie = useCookie('directus-auth')
      return cookie.value
    }

    set(value: AuthenticationData) {
      const cookie = useCookie('directus-auth')
      cookie.value = value as any
    }
  }

and then just do:

const directus = createDirectus<Schema>(directusURL, { globals: { fetch: $fetch } })
		.with(authentication('json', { storage: new CookieStorage() as any, credentials: 'include' }))
		.with(rest({ credentials: 'include' }))

@karndt84
Copy link

@maxsteinwand thank you very much, it works now.

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

No branches or pull requests

5 participants