I'm trying to determine if a client is currently authenticated or not. I'm calling directus.auth.refresh().then(()=>{...}).catch(()=>{...}); from the frontend and I noticed it never makes a network request to even check the authentication status. It always triggers the then and never the catch. And it does all this regarless if whether I'm actually logged in or not. My question is - is refresh() how I'm supposed to check if a client is authenticated? And, if so, how do I get refresh() to do something other than triggering the then() logic regardless of whether or not the user is authenticated?
#✅ SDK directus.auth.refresh() does nothing
6 messages · Page 1 of 1 (latest)
Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please make sure your question includes the following:
- An explanation of exactly what you're trying to achieve.
- Any and all related code or previous attempts.
- The exact issue or error you are facing.
- Any screenshots if applicable.
When you're done with this thread, please close it.
(If you have a support agreement and need help, please contact the core team via email.)
If the user is authenticated you may also try await directus.users.me.read(); which will return the current user’s info.
I tried the version published moments ago to no avail. I’ll try the users method for now. Should I create a GitHub issue for the refresh() in the meantime?
Refresh isn’t really meant to be called to see if the user is logged in or not, so this seems less bug and more how it’s being used, refresh will try to reset their tokens if they are logged in so it’s not really meant to be used as a way to see if they’re logged in or not.
I’d try calling the .me I mentioned which if the user is logged in it will return their record.
✅ SDK directus.auth.refresh() does nothing