nuxt-directus icon indicating copy to clipboard operation
nuxt-directus copied to clipboard

Support for OAuth Logins ?

Open Jan0707 opened this issue 2 years ago • 13 comments

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 🙏

Jan0707 avatar Nov 22 '23 14:11 Jan0707

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 avatar Jan 14 '24 11:01 casualmatt

@casualmatt doesn't SSO work on the v5 ?

Nisthar avatar Mar 04 '24 13:03 Nisthar

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 avatar Mar 04 '24 13:03 casualmatt

@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

Nisthar avatar Mar 04 '24 13:03 Nisthar

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 avatar Mar 04 '24 13:03 casualmatt

@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?

Nisthar avatar Mar 06 '24 13:03 Nisthar

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.

casualmatt avatar Mar 06 '24 14:03 casualmatt

@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

sandros94 avatar Mar 06 '24 14:03 sandros94

any news on this?

iprokhorov avatar Sep 28 '24 21:09 iprokhorov

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

sandros94 avatar Sep 29 '24 00:09 sandros94

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

zenojunior avatar Nov 18 '24 21:11 zenojunior

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

Currently loginWithProvider just does a redirect to a oauth url, and does not set any states.

Intevel avatar Nov 19 '24 07:11 Intevel

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.

yavuz avatar Jan 16 '25 15:01 yavuz