D
D
Daniil Chashkov2018-08-17 17:46:21
Laravel
Daniil Chashkov, 2018-08-17 17:46:21

Laravel+Vue: Authorization, registration - how to do it?

How to implement user authorization and registration in Laravel using Vue?
I read about jwt auth, but then they advised laravel passport, and I don’t know what to do.
My suggestion:
Write a controller that will have methods, login, register, logout.
And accordingly the controller will be attached to the routes - /sign, /exit, /signin.
Then from vue components make requests for these routes.
Then the question arises - how to display text in vue components that should be visible only to authorized users.
Second assumption:
Use standard controllers then - how to change what controllers should return? how to display text in vue components that should be visible only to authorized users?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Ba An Doan, 2018-08-18
@doanbaanh

Laravel (JWT):
Installing and configuring the jwt-auth package is well documented . What about the controller - CTRL + C and CTRL + V. Also don't forget about CORS.
Vue:
You don't have to go far either. There is a wonderful package vue-auth , which itself stores the token in localStorage, pulls it out and inserts it into the header on requests. This goodness is integrated in 5 minutes.
And the actual display only to authorized users:
Hint if you're working with these packages:
Vue-auth plucks the token from the header, not from the body of the response. And in the jwt-auth documentation in the controller, the token is inserted into the response body. A small modification of the controller is needed:

protected function respondWithToken($token)
    {
        return response()->json([
            'status' => 'success',
        ])->header('Authorization', $token);
    }

A
Akim Glushkov, 2018-08-18
@mikaakim

a token is placed in localStorage, the registration state can be stored in Vuex. Already show a message as, under certain conditions, you can google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question