From 93fc7889449868ce47475dc6c5ca76d7f69571c4 Mon Sep 17 00:00:00 2001 From: Dennis Elsinga Date: Fri, 20 Sep 2024 14:47:19 +0200 Subject: [PATCH] Add default user credentials for local development --- .env.example | 3 +++ README.md | 10 +++++++++- app/Filament/Pages/Auth/Login.php | 4 ++-- config/app.php | 9 +++++++++ database/seeders/UserSeeder.php | 4 +++- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 9f4bb52..513fbdd 100644 --- a/.env.example +++ b/.env.example @@ -64,3 +64,6 @@ AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" DEBUGBAR_ENABLED=true + +DEFAULT_USER_EMAIL="admin@example.com" +DEFAULT_USER_PASSWORD="password" diff --git a/README.md b/README.md index a98f4c8..cec82b6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Kickstart your project and save time with Larament! This time-saving starter kit - The Filament Panel's primary color is set to blue. - Single Page Application (SPA) mode is enabled by default, providing faster and smoother user experiences. -- A custom login page auto-fills email and password with seeded data, removing the need for manual typing in local testing. +- A custom login page autofills email and password with seeded data, removing the need for manual typing in local testing. - Global search keybinding is preset to `CTRL + K` or `CMD + K` (for macOS) for quick access to search functionality. - A PEST test case for the `UserResource` ensures all functionalities are tested effectively. - The global user search includes email addresses in the search results for better user discovery. @@ -27,6 +27,14 @@ Kickstart your project and save time with Larament! This time-saving starter kit - All component labels are automatically translatable, so there’s no need to add `->translateLabel()` to individual components. - Archtest is included for architectural testing. +## Default User (Local) +By default, the first user will be created based on the credentials setup in the `.env` file. If you want to change the default user after running the seeders, you can update the `DEFAULT_USER_EMAIL` and `DEFAULT_USER_PASSWORD` in the `.env` file and run the seeders again. + +```dotenv +DEFAULT_USER_EMAIL="admin@example.com" +DEFAULT_USER_PASSWORD="password" +``` + ## [Helpers](https://laravel-news.com/creating-helpers) I've set up a Helper file for you to use in your Laravel app. You can find it at `app\Helpers.php`. This file is ready for you to add your custom helper functions, which Composer will automatically include in your project. diff --git a/app/Filament/Pages/Auth/Login.php b/app/Filament/Pages/Auth/Login.php index e3cf27b..5f17666 100644 --- a/app/Filament/Pages/Auth/Login.php +++ b/app/Filament/Pages/Auth/Login.php @@ -12,8 +12,8 @@ public function mount(): void if (app()->isLocal()) { $this->form->fill([ - 'email' => 'admin@example.com', - 'password' => 'password', + 'email' => config('app.default_user.email'), + 'password' => config('app.default_user.password'), 'remember' => true, ]); } diff --git a/config/app.php b/config/app.php index f467267..f702f27 100644 --- a/config/app.php +++ b/config/app.php @@ -123,4 +123,13 @@ 'store' => env('APP_MAINTENANCE_STORE', 'database'), ], + /* + * Default user credentials for local development environment + * This will be used as the default user credentials when seeding the database + */ + + 'default_user' => [ + 'email' => env('DEFAULT_USER_EMAIL'), + 'password' => env('DEFAULT_USER_PASSWORD'), + ], ]; diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index b39f153..4d42f7f 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -4,6 +4,7 @@ use App\Models\User; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Hash; class UserSeeder extends Seeder { @@ -11,7 +12,8 @@ public function run(): void { User::factory() ->create([ - 'email' => 'admin@example.com', + 'email' => config('app.default_user.email'), + 'password' => Hash::make(config('app.default_user.password')), 'name' => 'Admin', ]); }