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

Logout feature #7096

Closed
3 tasks done
jjgonc opened this issue Jul 30, 2021 · 13 comments
Closed
3 tasks done

Logout feature #7096

jjgonc opened this issue Jul 30, 2021 · 13 comments

Comments

@jjgonc
Copy link

jjgonc commented Jul 30, 2021

Preflight Checklist

Describe the Bug

Hey, I'm developing a login/logout feature into my frontend that is connected to directus and I'm using VUE3 and the SDK.

I posted this on discord and I they recommended me to open an issue here, so here it is xD

I have the logout button with the following code:
async logoutRequest() { await directus.auth.logout(); this.userInfo = null }

and to login I'm using :
await directus.auth.login({ email: this.email, password: this.password, }, { refresh: { auto:true, //auto-refresh the auth token once it's close to expire }, });

When I first click the logout button, the following appears into console:

Screenshot from 2021-07-30 14-40-51

then (lets suppose a user clicks again) if I click again without any user logged, the following appears:

Screenshot from 2021-07-30 14-42-20

Maybe I can be doing something wrong, but I've been recommended on discord to open the issue, so here it is 😄

To Reproduce

As described before, simply executing the logout the first time shows the refresh_token warning and at the second time (when logged out) shows the error and the warning

What version of Directus are you using?

v9.0.0-rc87

What version of Node.js are you using?

v14.17.2

What database are you using?

mySQL 8.0.25

What browser are you using?

Firefox

What operating system are you using?

Linux - Ubuntu 18.04.5 LTS

How are you deploying Directus?

terminal (npx directus start)

@rijkvanzanten
Copy link
Member

Do you have a custom value set for the REFRESH_TOKEN_TTL environment variable in Directus?

@jjgonc
Copy link
Author

jjgonc commented Jul 30, 2021

I didn't chage that value, but it is assigned in the .env files

@rijkvanzanten
Copy link
Member

Is the app you're calling this request from on the same domain/port as Directus? 🤔 (Cookies can be very very finicky on cross-domain and localhost)

@jjgonc
Copy link
Author

jjgonc commented Jul 30, 2021

My directus in in localhost:8055 and the frontend is localhost:8080

@rijkvanzanten
Copy link
Member

In the network tab, when making the login request, is the cookie being returned in the response headers?

@jjgonc
Copy link
Author

jjgonc commented Jul 30, 2021

Are you talking about the "Set-Cookie"? Is affirmative, yes!
It returns an directus_refresh_token=.....

@rijkvanzanten
Copy link
Member

What's the full cookie there? 🤔

@rijkvanzanten
Copy link
Member

And this is throwing that warning from before??? This cookie says it expires in august, which shouldn't cause a "is rejected because it's already expired" message eh? :o

@jjgonc
Copy link
Author

jjgonc commented Jul 30, 2021

I don't know what is throwing the warn, I also don't think it is because of this

@paescuj
Copy link
Member

paescuj commented Jul 30, 2021

is rejected because it's already expired

This is shown when a "HttpOnly" cookie is removed by the server - so this means the logout action was successful.

@paescuj
Copy link
Member

paescuj commented Jul 30, 2021

then (lets suppose a user clicks again) if I click again without any user logged, the following appears:

You need to catch this case in your frontend app - you can't logout if there's no active session.

@rijkvanzanten
Copy link
Member

With all the info provided, it looks like things are exactly working as expected 🙂

The logout action removes the refresh token by setting the expiry to 0, the next call to logout throws an error as the refresh token no longer exists 👍🏻

@jjgonc
Copy link
Author

jjgonc commented Jul 30, 2021

Thanks for the help, I'll tell the people out in discord so they know it is "normal"

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants