add me endpoint
This commit is contained in:
parent
b705d49aa1
commit
c0d0d070a8
5 changed files with 56 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ APP_ENV=local
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=https://localhost:8000
|
APP_URL=https://localhost:8000
|
||||||
|
FRONTEND_URL=https://localhost:5173
|
||||||
|
|
||||||
APP_LOCALE=en
|
APP_LOCALE=en
|
||||||
APP_FALLBACK_LOCALE=en
|
APP_FALLBACK_LOCALE=en
|
||||||
|
|
|
||||||
23
backend/app/Http/Controllers/AuthController.php
Normal file
23
backend/app/Http/Controllers/AuthController.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\User\User;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class AuthController extends Controller
|
||||||
|
{
|
||||||
|
public function me(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = $request->attributes->get('user');
|
||||||
|
|
||||||
|
return new JsonResponse([
|
||||||
|
'user' => [
|
||||||
|
'id' => $user->getId(),
|
||||||
|
'email' => $user->getEmail()->value(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ use Illuminate\Http\Request;
|
||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
web: __DIR__.'/../routes/web.php',
|
web: __DIR__.'/../routes/web.php',
|
||||||
|
api: __DIR__.'/../routes/api.php',
|
||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
health: '/up',
|
health: '/up',
|
||||||
)
|
)
|
||||||
|
|
|
||||||
22
backend/config/cors.php
Normal file
22
backend/config/cors.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$frontendUrl = (string) env(
|
||||||
|
'FRONTEND_URL',
|
||||||
|
'https://localhost:5173',
|
||||||
|
);
|
||||||
|
$allowedOrigins = array_values(array_unique([
|
||||||
|
$frontendUrl,
|
||||||
|
str_replace('localhost', '127.0.0.1', $frontendUrl),
|
||||||
|
str_replace('127.0.0.1', 'localhost', $frontendUrl),
|
||||||
|
]));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'paths' => ['api/*'],
|
||||||
|
'allowed_methods' => ['*'],
|
||||||
|
'allowed_origins' => $allowedOrigins,
|
||||||
|
'allowed_origins_patterns' => [],
|
||||||
|
'allowed_headers' => ['*'],
|
||||||
|
'exposed_headers' => [],
|
||||||
|
'max_age' => 0,
|
||||||
|
'supports_credentials' => true,
|
||||||
|
];
|
||||||
9
backend/routes/api.php
Normal file
9
backend/routes/api.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\AuthController;
|
||||||
|
use App\Http\Middleware\AuthMiddleware;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::middleware(AuthMiddleware::class)->group(function (): void {
|
||||||
|
Route::get('/me', [AuthController::class, 'me']);
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue