diadal / vue-social-auth

Laravel Vue (SPA) Social Auth
75 stars 27 forks source link

CALLBACK is problem #2

Closed JulioCCosta closed 5 years ago

JulioCCosta commented 5 years ago

I have two projects (api = laravel and client = vuejs) my real problem is that in the callback it redirects me to my api, how do I return to my client?

diadal commented 5 years ago

create from your Api route


Route::post('api/sociallogin/{provider}', 'YourAuthController@SocialSignup');
Route::post('api/auth/{provider}', 'YourOutController@index')->where('vue', '.*');
Route::post(api/'auth/{provider}/callback', 'YourOutController@index')->where('vue', '.*');

than


YourAuthController

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use Socialite;

class AuthController extends Controller
{

    public function __construct()
    {

    }

    public function SocialSignup($provider)
    {
        // Socialite will pick response data automatic 
        $user = Socialite::driver($provider)->stateless()->user();

        return response()->json($user);
    }

}
JulioCCosta commented 5 years ago

@diadal I'm doing this, the problem is that in my client (vuejs) when I try to callback the package it only returns the code and not the token

socialcontroller image

` Vue.use(VueSocialauth, { baseUrl: API_URI, // Your API domain

providers: { github: { url: "http://localhost:8000/", clientId: '5c1fc8a9f5b57128f3b4', redirectUri:window.location.origin + "/login"

}

} })`

diadal commented 5 years ago

this return response()->json($user); and dd($user) are different

diadal commented 5 years ago

make sure your callback route point back to your index page Route::post(api/'auth/{provider}/callback', 'YourOutController@index')->where('vue', '.*')

then

Vue Router

        {
          path: 'api/auth/:provide/callback',
          component: {
            template: '<div class="auth-component"></div>'
          }
        },