<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Route;
use Laravel\Socialite\Facades\Socialite;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('home');
}) -> name('home');


Route::group(['middleware' => 'guest'], function(){
    
    Route::get('/register', [UserController::class, 'create']) -> name('register.create');
    Route::post('/register', [UserController::class, 'store']) -> name('register.store');
    Route::get('/login', [UserController::class, 'loginForm']) -> name('login.create');
    Route::post('/login', [UserController::class, 'login']) -> name('login');
    
});

Route::group(['middleware' => 'auth'], function(){

    Route::get('/logout', [UserController::class, 'logout']) -> name('logout');
    Route::get('/settings', [UserController::class, 'settings']) -> name('settings');
    
});


//Auth Google
Route::get('/login/google', function () {
    return Socialite::driver('google')->redirect();
}) -> name('login.google');

Route::get('/login/google/callback', [UserController::class, 'loginGoogle']) -> name('register.store');





//Auth Facebook
Route::get('login/facebook', function () {
    return Socialite::driver('facebook')->redirect();
}) -> name('login.facebook');
Route::get('login/facebook/callback', function () {
    $user = Socialite::driver('facebook')->user();
    // $user->token
});












