Hello, currently writing an app where I did a lot of authentication myself.
It works fine, but it’s decently buggy after several attempted fixes so I’m migrating it to authentication using the SDK.
Docs look clear, implementation looks straight-forward, but wondering about a few things.
-
Is the client a shared singleton? If I create the client in one file and use it in another, do I get access to the same instance of the client? Is a context required?
-
I use middleware right now to determine if someone is authenticated (based on a cookie) and then if they aren’t I redirect them to log in. Is there a way to do this with the Directus SDK?
-
I re-log someone in automatically using the refresh token in cookies. Is this supported?
Thanks!
Thanks for the response. In React, do you recommend context, or something else? Can I call sdk.getToken() in NextJS middleware? Does the SDK handle auto login if a refresh token exists? Or would that still be up to me.
– masonI am not familiar enough with react or next.js to recommend anything specific. I would refer to our sample implementation of authentication with next.js as a good starting point. The sdk does handle auto refresh if the original login was done with the authentication composable.
– comfortablycoding