PepperFM
PepperFM
FFilament
Created by Pritbor on 2/23/2024 in #❓┊help
Adding Mobile OTP verification in Filament registration and login.
its about laravel, not filament btw i have latest environment: php: 8.3.3 laravel: 10.47.0 filament: 3.2.46
8 replies
FFilament
Created by Pritbor on 2/23/2024 in #❓┊help
Adding Mobile OTP verification in Filament registration and login.
yep. i had override base laravel session with my custom well, actually its should be another topic, but for short, i will leave example here:
AppServiceProvider

use App\Overrides\Auth\EloquentUserProvider; <-- class extends \Illuminate\Auth\EloquentUserProvider
use App\Overrides\Auth\UserProvider; // <-- contract extends \Illuminate\Contracts\Auth\UserProvider

register()
{
// some DI
$this->overrideSession();
}

private function overrideSession(): void
{
$this->app->singleton(
UserProvider::class,
static fn(Application $app) => new EloquentUserProvider(
hasher: $app->make('hash'),
model: config('auth.providers.users.model')
)
);
$this->app['auth']->extend(
'filament-session',
static function (Application $app) {
$guard = new SessionGuard(
name: 'filament-session',
provider: $app->make(UserProvider::class),
session: $app->make('session.store'),
request: $app->make('request')
);
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($app->make('cookie'));
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($app->make('events'));
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
}

return $guard;
}
);
}
AppServiceProvider

use App\Overrides\Auth\EloquentUserProvider; <-- class extends \Illuminate\Auth\EloquentUserProvider
use App\Overrides\Auth\UserProvider; // <-- contract extends \Illuminate\Contracts\Auth\UserProvider

register()
{
// some DI
$this->overrideSession();
}

private function overrideSession(): void
{
$this->app->singleton(
UserProvider::class,
static fn(Application $app) => new EloquentUserProvider(
hasher: $app->make('hash'),
model: config('auth.providers.users.model')
)
);
$this->app['auth']->extend(
'filament-session',
static function (Application $app) {
$guard = new SessionGuard(
name: 'filament-session',
provider: $app->make(UserProvider::class),
session: $app->make('session.store'),
request: $app->make('request')
);
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($app->make('cookie'));
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($app->make('events'));
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
}

return $guard;
}
);
}
in my EloquentUserProvider i had override validateCredentials() method to check only phone + config/auth.php
'guards' => [
'web' => [
'driver' => 'filament-session',
'provider' => 'users',
],
],
'guards' => [
'web' => [
'driver' => 'filament-session',
'provider' => 'users',
],
],
8 replies
FFilament
Created by Pritbor on 2/23/2024 in #❓┊help
Adding Mobile OTP verification in Filament registration and login.
8 replies