[Vuejs]-Laravel Vue SPA – Social Authentication

0👍

You need Laravel Socialite to get data about user from the identity provider (it could be Google, Github, Facebook or something else). It will use Oauth2 protocol.
You will store client_id and client_secret from the third party authentication you want to use. User will click for example Sign up with Google and it will redirect him to Google login page. If he fills correct username and password you will get his user information by using Socialite::driver(‘github’)->user() .

You can use updateOrCreate() method to create user if it doesn’t already exist in your database or just to update his data. Email or username fields could be identifiers or whatever is unique and works for your case.

After you found the user in database or created a new one, you should log in him to your application using session cookie or some kind of token.
Whole auth proccess is happening on the backend side, only when you successfully log in user to your app you can issue cookie to the frontend Vue side. So to answer your question, yes you can use Socialite with SPA.

Don’t mix Laravel Socialite/Oauth2 with authentication proccess/Laravel Sanctum.

Former is for retrieving user data without registering on your site. Latter is for actually giving access to your API for specific user.

Leave a comment