Search code examples
vue.jsauthenticationjwtnuxt.jsnuxt-auth

How to authenticate multiple api using Nuxt and nuxt-auth module


I have an application with (nuxt js using nuxt-auth) with local authentication so far (later I want to add git and google auth).

Now I need to add authentication to invoke other services / API (like google cloud rest API, payment system, youtube API, etc...)

The question is: the user is authenticated only once (during login to the application.) but each of these 3rd party APIs has its own authentication.

How to implement multiple authentications. (I read the documentation and google for the entire day but there is no clear answer).


Solution

  • As of today, it looks like it is not doable (people are needed on this module): https://github.com/nuxt-community/auth-module/issues/889

    So, you would need to make it manually by plugging the APIs yourself.

    Answer to your latest question~comment

    Nuxt is indeed nice with some of it's modules (but you can totally dislike it, no problem :D).

    First thing that you need to know, is that this project (nuxt-auth) is not the biggest one, @pooya is doing his best but he is on a lot of projects, so he cannot give all of his love to it. Then, you also need to understand that it's working great but it's still in a decent beta state with a lot of missing features, needed documentation and a lot of small things to make it an all rounded solid top notch solution.

    That do not mean that you should not use it, I'm just saying that this module do have some limitations. Hence, the fact that it is not supporting a whole lot of OAuth solutions in a clear + simple + flexible way. And some breaking changes may be introduced in future updates.

    The module is aimed towards having an OAuth solution to block the content of your website behind it (in my opinion). It means that you will usually use a single login solution and then, being able to have access to your app. I don't think that it's a viable multi-OAuth solution (yet).

    Some services don't even need to use a solution like this. Stripe for example, should not be handled on the frontend but communicate with a backend for sensitive variables and just send minimal info thanks to Stripe Elements.

    That said, the most common solution is JWT or OAuth2, and you could totally have a backend service or service like Okta, Auth0 or alike, do the heavy lifting by allowing simple logins to providers (Github, Google etc...).

    To sum up, you do connect to this backend/service thanks to nuxt-auth, the service itself does the provider connection and you get the best of both worlds while still connected in a secure way through your initial nuxt-auth entry point login.

    Or you could try to reach the community on Discord, see if somebody knows how to do it. Or even try to read the source code to see if it is currently feasable.

    And that's my 2cts.