Support for OAuth Logins ?
Hi 👋
Our directus instance currently only supports login via OAuth (e.g. github).
We would like to use this package, but it seems like you only support login via username/password (e.g. see documentation here: https://nuxt-directus-docs.vercel.app/composables/usedirectusauth#login )
Our current workaround is to manually include a "Login via XYZ" button in the nuxt frontend and have that then again redirect to the nuxt website once, the login/auth flow has completed.
However, when I then try to access the user:
const { fetchUser, setUser } = useDirectusAuth();
let user = useDirectusUser();
if (!user.value) {
const user = await fetchUser();
console.log("Fetched User", user);
setUser(user.value);
}
I only ever get undefined.
Am I missing something or is the whole user composable simply not fit to support this use case?
Any hint would be highly appreciated 🙏
Hi @Jan0707, Sorry for not getting back to you sooner; SSO is possible with the new v6 module out in beta; we are populating the documentation in the next few weeks.
--> Here is an example from directus documentation: https://docs.directus.io/self-hosted/sso.html
@casualmatt doesn't SSO work on the v5 ?
I don't think so. Probably manually, yes (but you are on your own.). v6 will support it because v6 is based on the SDK.
@casualmatt i am confused which one should i use in my app? i prefer to try v6 but i am not sure if it has everything v5 has
It does, and it adds more stuff.
But we are building the docs, so you must use the IntelliSense and comments on the discussion to navigate it.
@casualmatt just found this https://docs.directus.io/releases/breaking-changes.html#session-cookie-based-authentication it was for their last update. would this affect the auth module of v6?
Just last night @Sandros94 sent it to me, I think we will take a look at it one of those evening. But I don't think we will support it for 6.0 more for 6.1/2
But in the new module u will be able to use the SDK to manage the session/cookie. And that way should already work from 6.0. U can try it, by using the "next" version of the module and disabling Nuxt cookie in the config.
@Nisthar @casualmatt
Once we solve #242 I will start working on this. I could even be able to add it as an optional mode even for 6.0.
But considering the nature of this topic, the process will mostly depend on potential upstream issues
any news on this?
any news on this?
The SDK rewrite has been canceled and went back to a nuxt-first approach (RFC #271, current progress #273).
This being said once that PR gets merged this should be available (in the nuxt-directus-next package), but unfortunately I had to slow down its development because of other projects.
Will update as I go along, but could take a bit, since I still need to refactor most of user's authentication yet
The login using the loginWithProvider method works, and when accessing the Directus app, I am logged in. However, const user = useDirectusUser() returns undefined
Directus (CMS): v11.0.2 nuxt-directus: ^5.7.0
Do you have any estimates for solving this problem? Thanks! And congratulations on the great work on this library
The login using the
loginWithProvidermethod works, and when accessing the Directus app, I am logged in. However, constuser = useDirectusUser()returns undefinedDirectus (CMS): v11.0.2 nuxt-directus: ^5.7.0
Do you have any estimates for solving this problem? Thanks! And congratulations on the great work on this library
Currently loginWithProvider just does a redirect to a oauth url, and does not set any states.
When attempting to log in with loginWithProvider, Google redirects back to the Directus URL for the callback, where the login process occurs. After that, it redirects back to Nuxt. However, since no data is returned to Nuxt, the state on the Nuxt side doesn't change.
If we don't use the Google Auth section in Directus and try to create a user with the data coming from Nuxt, I'm not sure how we would handle the login process. This is because the login method requires sending a username and password.
If anyone has another idea for the OAuth feature, I’ll try to implement it.