resolve the confilict code

This commit is contained in:
2026-04-26 09:42:24 +03:30
parent 086323e07a
commit c957a60a93
3 changed files with 43 additions and 42 deletions

View File

@@ -1,39 +0,0 @@
<?php
namespace app\User\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
class AuthController extends Controller
{
public function redirectToGoogle():RedirectResponse
{
return Socialite::driver(['google', 'facebook'])->redirect();
}
public function registerGoogle():JsonResponse
{
$googleUser = Socialite::driver(['google', 'facebook'])->user();
$data = User::query()->updateOrCreate([
'email' => $googleUser->email,
'name' => $googleUser->name,
'password' => Hash::make(Str::random(10)),
'google_token' => $googleUser->token,
'google_refresh_token' => $googleUser->refreshToken,
]);
return response()->json(
$data
);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\User\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
class AuthController extends Controller
{
public function redirectToGoogle($driver):RedirectResponse
{
return Socialite::driver($driver)->redirect();
}
public function registerGoogle($driver):JsonResponse
{
$socialUser = Socialite::driver($driver)->user();
$user = User::updateOrCreate(
['email' => $socialUser->getEmail()],
[
'name' => $socialUser->getName(),
'password' => Hash::make(Str::random(16)),
]
);
$token = $user->createToken('auth_token')->accessToken;
return response()->json([
'user' => $user,
'access_token' => $token,
'token_type' => 'Bearer',
]);
}}

View File

@@ -1,11 +1,11 @@
<?php
use app\User\Auth\AuthController;
use App\User\Controllers\Auth\AuthController;
use Illuminate\Support\Facades\Route;
Route::prefix('Auth')
->controller(AuthController::class)
->group(function () {
Route::get('google/redirect', 'redirectToGoogle')->name('google.redirect');
Route::get('google/registerGoogle', 'registerGoogle')->name('google.registerGoogle');
Route::get('{driver}/redirect', 'redirectToGoogle')->name('redirect');
Route::get('{driver}/registerGoogle', 'registerGoogle')->name('registerGoogle');
});