Help: structure site with Vue js, Server web and Server API

0

how are you? I wanted to consult if there is any way that is styled, either in performance or directly as good practices, for the following: The application of the web side is with Vue js, there will also be an API to be consumed by both web and mobile applications. On the side of the Server I use Laravel.

So, what I want is to consume the API always from the web client, but first I should log in. If I log in via web, then I would need the server to return the index, which will contain the complete compilations to work with Vue, but when I want to start consuming the API, I would be missing the token (as if I had been via API with passport or any other). The Server API could be on another server than the web. Queries: .- Is it correct to log in the web server, and that it is logged in the server API? Then he will continue working against the web, and that he will use proxies to communicate with the API. That is, the web part would act as a handrail only.

.- The other one is that I loguee against the web, that it logs against the API and manages to return that token to the web client, and then start only to interact with the API. With this, they would leave the web server a bit obsolete, since I would be using it just to log in and give me all the Vue files, now.

.- The last one, is to start from the login form (that the user should get it in some way), then log in, and then get the Vue compilations to continue consuming the API. What is not clear to me, and I mean better practices to avoid wasting resources, is, in this scenario, how to get to the Login form, and more important, once logged against the API, get the full site in Vue, post that the API should not give you this kind of information, is that correct? Sorry if the query was extensive. I hope you understood what I want to do.

The query is more oriented to what is the best practice or what is styled in these cases. Thank you !! Greetings!

G.

    
asked by Gaston Silva 30.07.2018 в 23:22
source

1 answer

0

I'm in an almost identical project. I would think that the login should be part of the Vue app and only move to other components (with the Vue routing functionalities) if the authentication has been exceeded. With this you manage that all the files of your app are served at one time, and not having to make several requests to the server for the same app, which in my opinion, does not go very well with the philosophy of the Single Page Aplication. / p>

When the app is served, the token can already be included from the server and you would not have any problem in using it for authentication and have it available later when necessary.

If done this way, you can get rid of an intermediate server and only consult the API with Vue and manage all the logic with Javascript, even save the token in cache or in cookies for other functions.

    
answered by 02.08.2018 в 16:42