From 237ea299cd8177fcbd8f6ca77d5a7ea331ba2758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna-Sara=20S=C3=A9lea?= Date: Sun, 20 Apr 2025 22:02:00 +0200 Subject: [PATCH] Backend: Fix with Endpoints --- bootstrap/app.php | 1 + config/sanctum.php | 83 +++++++++++++++++++ ...47_create_personal_access_tokens_table.php | 33 ++++++++ routes/api.php | 10 +++ routes/web.php | 21 +++-- 5 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 config/sanctum.php create mode 100644 database/migrations/2025_04_19_193647_create_personal_access_tokens_table.php create mode 100644 routes/api.php diff --git a/bootstrap/app.php b/bootstrap/app.php index 113955b..461aafd 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', + api: __DIR__.'/../routes/api.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) diff --git a/config/sanctum.php b/config/sanctum.php new file mode 100644 index 0000000..764a82f --- /dev/null +++ b/config/sanctum.php @@ -0,0 +1,83 @@ + explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( + '%s%s', + 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', + Sanctum::currentApplicationUrlWithPort() + ))), + + /* + |-------------------------------------------------------------------------- + | Sanctum Guards + |-------------------------------------------------------------------------- + | + | This array contains the authentication guards that will be checked when + | Sanctum is trying to authenticate a request. If none of these guards + | are able to authenticate the request, Sanctum will use the bearer + | token that's present on an incoming request for authentication. + | + */ + + 'guard' => ['web'], + + /* + |-------------------------------------------------------------------------- + | Expiration Minutes + |-------------------------------------------------------------------------- + | + | This value controls the number of minutes until an issued token will be + | considered expired. This will override any values set in the token's + | "expires_at" attribute, but first-party sessions are not affected. + | + */ + + 'expiration' => null, + + /* + |-------------------------------------------------------------------------- + | Token Prefix + |-------------------------------------------------------------------------- + | + | Sanctum can prefix new tokens in order to take advantage of numerous + | security scanning initiatives maintained by open source platforms + | that notify developers if they commit tokens into repositories. + | + | See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning + | + */ + + 'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''), + + /* + |-------------------------------------------------------------------------- + | Sanctum Middleware + |-------------------------------------------------------------------------- + | + | When authenticating your first-party SPA with Sanctum you may need to + | customize some of the middleware Sanctum uses while processing the + | request. You may change the middleware listed below as required. + | + */ + + 'middleware' => [ + 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, + 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, + 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, + ], + +]; diff --git a/database/migrations/2025_04_19_193647_create_personal_access_tokens_table.php b/database/migrations/2025_04_19_193647_create_personal_access_tokens_table.php new file mode 100644 index 0000000..e828ad8 --- /dev/null +++ b/database/migrations/2025_04_19_193647_create_personal_access_tokens_table.php @@ -0,0 +1,33 @@ +id(); + $table->morphs('tokenable'); + $table->string('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + $table->timestamp('last_used_at')->nullable(); + $table->timestamp('expires_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('personal_access_tokens'); + } +}; diff --git a/routes/api.php b/routes/api.php new file mode 100644 index 0000000..2b43752 --- /dev/null +++ b/routes/api.php @@ -0,0 +1,10 @@ +name('register_customer'); +Route::post('register_purchase', [PurchaseController::class, 'store'])->name('register_purchase'); +Route::post('register_deposit/{id}', [CustomerController::class, 'updateDeposit']); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 067c4f5..d8e35e2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,19 +4,22 @@ use App\Http\Controllers\ProfileController; use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Route; use Inertia\Inertia; +use App\Http\Controllers\CustomerController; Route::get('/', function () { - return Inertia::render('Welcome', [ - 'canLogin' => Route::has('login'), - 'canRegister' => Route::has('register'), - 'laravelVersion' => Application::VERSION, - 'phpVersion' => PHP_VERSION, - ]); + return Inertia::render('Auth/Login'); }); -Route::get('/dashboard', function () { - return Inertia::render('Dashboard'); -})->middleware(['auth', 'verified'])->name('dashboard'); +Route::get('/dashboard', [CustomerController::class, 'index'])->middleware(['auth', 'verified'])->name('dashboard'); +Route::get('/customer/{id}', [CustomerController::class, 'show'])->middleware(['auth', 'verified']); + +Route::get('/form', function () { + return Inertia::render('Form'); +})->name('form'); + +Route::get('/thankyou', function () { + return Inertia::render('Thankyou'); +})->name('thankyou'); Route::middleware('auth')->group(function () { Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');