![]() Add the following code to your LoginController file. So in order to prevent that, we need to add user_logged_out session by overriding laravel’s default logout method in LoginController.php. Now, if user chooses to logout of our application we should not login him/her again with Facebook. Since Vue performs 2 way binding, it automatically updates the elements as soon as there is a change. ![]() If our response status from authenticate is true we will update our Vue variables. If there is no user, then we will send status as false. If we have a user then we are going to log him in and return the user details as json response. Here, we will get the user’s facebook id and perform a database check. Authenticate route will in turn call method. If our condition is true, we are going to authenticate our user by sending request to authenticate route using axios. Here, we are checking if response status is connected, which means, he is authenticated user and he is currently logged in to the facebook. If user is indeed signed in, then it will execute the statusChangeCallback functionĪpp.statusChangeCallback is Vue method and has facebook response as parameter ![]() But now, lets break the code and review it one by one for better understanding.Ībove code will hit facebook server and return user’s data if user have already logged into our application via facebook previously and currently he is logged into facebook on one of his browser tabs. Thats all you require to achieve automatic facebook login. After removing app.js, modify login, register list item in like the below For this article purpose I’m going to use cdn version of vue js and axios instead of using any package bundler like webpack. First, we have to remove laravel’s app.js file since we do not need that. Modify the to something like below by removing unnecessary codes.Īnd then lets modify inside layouts folder. We will create a separate controller called FacebookController.php to manage facebook login functionality php artisan make:controller FacebookController.phpĪfter creating the controller, add the following methods to FacebookController.php Add the following html code at the close of div panel-body tag For that we need to modify our little bit. First, we need our user to register with our application via facebook. php artisan make:authĪbove command will give us the boiler plate. env file Configuring Social Loginįor our application we are going to use laravel’s inbuilt authentication system just to save us some time. Now that our application is ready, lets install laravel socialite package and add its facade and provider class in config/app.phpĪfter registering add the following code to your services.php file Once that is done, migrate the table and add facebook_id to fillable array in User model. Also do not forget to set password field as nullable (since we’ll not get password from facebook) and without setting it to nullable will result in exception while creating Facebook user. Once your installation is complete, we will add facebook_id column to user migration file. So, here I’m going to walk you through step by step procedure to achieve the same.įirst, lets create a new laravel application. However, wouldn’t it be cool to perform automatic Facebook login to our user if he has already logged in once previously? Recently, while working on one of my project, I stumbled upon this scenario and I achieved this easily using Vue. Laravel socialite provides a nice wrapper for implementing Facebook social login in laravel framework.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |