A
A
Anton Shelestov2018-07-18 17:18:07
Laravel
Anton Shelestov, 2018-07-18 17:18:07

Laravel + Vue.js + SPA how to work in SPA as an authorized user?

Hello.
I just started learning Vue and decided to try making a small admin panel in the style of a SPA application. And I did not understand how to work in such an admin panel for an authorized user.
Now I have the following experience:
1. Authorization, registration, etc. work on regular post get requests without Vue
2. And the admin panel (after authorization) already uses Vue
And already in the code of the admin panel itself, code like:
if(Sentinel::check())
Does not work ... always returns false even if I successfully logged in earlier... I looked at jwt-auth.readthedocs.io/en/develop
, but somehow it's completely incomprehensible... Can anyone tell me how to properly configure authorization in the SPA application? Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Novikov, 2018-07-18
@dvnovikov

Why not take out the authorization in Vue?
When authorizing, put the user data in localstorage, which the back will give you. When reloading the page, check if there is info in storage. If not, then try to ask her from the back if you are authorized there. If yes, then fill in the storage again, if not, then throw it to hell for authorization

A
Andrey K, 2018-07-20
@kuftachev

In fact, it can be divided into two options.
1. Authorization through the session using the framework. Then cookies are registered, authorization can be left on the page without Vue, and then the browser itself sends cookies and the user is through the session. In this case, it is necessary that the static and the server are on the same port, otherwise it will not work.
2. Full-fledged authorization based on a token, it must be issued both on the client and on the server. As I understand it, the modern approach is JWT. In this case, the client and server may not be connected at all, they simply implement a common API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question