Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Bauhaususer Laravel Package

krafthaus/bauhaususer

Adds a simple login/user system for the Bauhaus admin package. Installs via Composer, registers the service provider, updates Bauhaus auth permission to use Auth::check(), switches the auth model to BauhausUser\User, runs migrations, and creates users via Artisan.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require krafthaus/bauhaususer:dev-master
    

    Add the service provider to config/app.php:

    'providers' => [
        KraftHaus\Bauhaus\BauhausServiceProvider::class,
        KraftHaus\BauhausUser\BauhausUserServiceProvider::class,
    ],
    
  2. Configure Auth: Update config/packages/krafthaus/config/admin.php:

    'auth' => [
        'permission' => function () { return Auth::check(); },
    ],
    

    Update config/auth.php:

    'model' => KraftHaus\BauhausUser\User::class,
    
  3. Run Migrations:

    php artisan migrate --package=krafthaus/bauhaususer
    
  4. First Use Case: Create a user via Artisan:

    php artisan bauhaus:user:create --email=admin@example.com --password=secret
    

    Test login via Bauhaus admin panel (e.g., /admin/login).


Implementation Patterns

Workflows

  1. User Management:

    • CRUD via Artisan:
      # Create
      php artisan bauhaus:user:create --email=user@example.com --password=pass123
      
      # List
      php artisan bauhaus:user:list
      
      # Update
      php artisan bauhaus:user:update 1 --email=new@example.com
      
      # Delete
      php artisan bauhaus:user:delete 1
      
    • Programmatic Access:
      use KraftHaus\BauhausUser\User;
      
      $user = User::where('email', 'user@example.com')->first();
      $user->update(['password' => bcrypt('newpass')]);
      
  2. Integration with Bauhaus:

    • Middleware: Use auth middleware (Laravel’s built-in) to protect Bauhaus routes.
    • Policies: Attach Laravel policies to KraftHaus\BauhausUser\User for granular permissions:
      use KraftHaus\BauhausUser\User;
      
      class PostPolicy {
          public function update(User $user, Post $post) { ... }
      }
      
  3. Customization:

    • Extend User Model: Add fields to the users table via migrations, then extend the model:
      namespace KraftHaus\BauhausUser;
      
      class User extends \KraftHaus\BauhausUser\User {
          protected $fillable = ['name', 'role']; // Add custom fields
      }
      
    • Override Auth Logic: Extend the BauhausUserServiceProvider to modify authentication behavior.
  4. API Integration:

    • Use Laravel’s Auth::attempt() or Auth::login() for API-based logins:
      if (Auth::attempt(['email' => $email, 'password' => $password])) {
          return response()->json(Auth::user());
      }
      

Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • If the users table already exists, drop it or manually merge migrations to avoid schema conflicts.
    • Fix: Backup your database before running migrations.
  2. Auth Guard Mismatch:

    • Ensure config/auth.php uses the correct guard (e.g., web or api) and that the model points to KraftHaus\BauhausUser\User.
    • Debug: Check Auth::user() returns null if misconfigured.
  3. Permission Logic:

    • The auth.permission callback in admin.php must return true or false synchronously. Async logic (e.g., DB queries) may cause issues.
    • Fix: Use Auth::check() directly or cache permission checks.
  4. Artisan Command Errors:

    • Commands like bauhaus:user:create may fail if the users table lacks required columns (e.g., password).
    • Fix: Re-run migrations or inspect the users table schema.

Debugging Tips

  1. Check Auth Events:

    • Listen for auth.attempting, auth.failed, or auth.logout events in EventServiceProvider:
      protected $listen = [
          'auth.failed' => [\App\Listeners\LogFailedLogin::class],
      ];
      
  2. Verify Middleware:

    • Ensure routes using Bauhaus are protected with auth middleware:
      Route::middleware(['auth'])->group(function () {
          Route::get('/admin', 'AdminController@index');
      });
      
  3. Logging:

    • Add debug logs to the BauhausUserServiceProvider boot method:
      public function boot() {
          \Log::info('BauhausUser initialized with model:', [User::class]);
      }
      

Extension Points

  1. Custom User Fields:

    • Add columns to the users table, then extend the model:
      // Migration
      Schema::table('users', function (Blueprint $table) {
          $table->string('api_token')->nullable();
      });
      
      // Model
      class User extends \KraftHaus\BauhausUser\User {
          protected $fillable = ['api_token'];
      }
      
  2. Override Login Logic:

    • Publish the package’s views and templates:
      php artisan vendor:publish --provider="KraftHaus\BauhausUser\BauhausUserServiceProvider"
      
    • Customize resources/views/vendor/bauhaususer/auth/login.blade.php.
  3. Multi-Auth:

    • Use Laravel’s guard() helper to switch between BauhausUser and other auth systems:
      if (Auth::guard('bauhaus')->attempt($credentials)) {
          // ...
      }
      
    • Note: Requires configuring a custom guard in config/auth.php.
  4. Testing:

    • Use Laravel’s actingAs helper for tests:
      $user = User::factory()->create();
      $this->actingAs($user)->get('/admin')->assertOk();
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle