jaracas wrote a reply+100 XP
5mos ago
jaracas wrote a reply+100 XP
5mos ago
I've updated my Providers\FortifyServiceProvider.php to:
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Inertia\Inertia;
use Laravel\Fortify\Contracts\LoginResponse;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->instance(LoginResponse::class, new class implements LoginResponse {
public function toResponse($request)
{
$user = $request->user();
if ($user && $user->characters()->count() > 0) {
return redirect('characters');
}
return redirect('characters/creator');
}
});
}
...
However it still isn't working
edit: I've made some progress, now I get a modal popup that says "App\Http\Responses\LoginResponse"
My code: App\Http\Responses:
<?php
namespace App\Http\Responses;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
class LoginResponse implements LoginResponseContract
{
/**
* @param $request
* @return mixed
*/
public function toResponse($request)
{
$user = auth()->user();
if ($user && $user->characters()->count() > 0) {
return redirect()->intended('/characters');
}
return redirect()->intended('/characters/creator');
}
}
FortifyServiceProvider:
public function register(): void
{
// https://laravel-news.com/override-login-redirects-in-jetstream-fortify
$this->app->instance(LoginResponseContract::class, LoginResponse::class);
$this->app->instance(TwoFactorLoginResponse::class, LoginResponse::class); // singleton
}
edit 2: After some research, I figured out it IS redirecting to where I want, but it re-redirects to /dashboard after that?
jaracas liked a comment+100 XP
5mos ago
jaracas wrote a reply+100 XP
5mos ago
jaracas wrote a reply+100 XP
5mos ago
I saw that in another thread while trying to solve things, however it never seems to work for me. What am I doing wrong? All it does is redirect me to /dashboard
<?php
use App\Http\Middleware\HandleAppearance;
use App\Http\Middleware\HandleInertiaRequests;
use Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware;
use Illuminate\Auth\Middleware\RedirectIfAuthenticated;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
use Illuminate\Http\Request;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
channels: __DIR__.'/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->encryptCookies(except: ['appearance', 'sidebar_state']);
$middleware->web(append: [
HandleAppearance::class,
HandleInertiaRequests::class,
AddLinkHeadersForPreloadedAssets::class,
VisitMonitoringMiddleware::class,
]);
$middleware->redirectUsersTo(function(Request $request) {
$user = auth()->user();
if ($user && $user->characters()->count() > 0) {
$route = 'game.characters';
} else {
$route = 'game.character_creator';
}
return route($route);
});
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();
jaracas started a new conversation+100 XP
5mos ago
I'm struggling to figure out how to add logic to redirect users after they login to different pages depending on whether they have data in another table or not.
I need to be able to redirect users after they login using the Laravel built-in auth (Vue starter kit not using WorkOS). Where exactly is the logic that determines where the user is sent after logging in? Right now no matter what I do it redirects to /dashboard.
jaracas wrote a reply+100 XP
5mos ago
jaracas started a new conversation+100 XP
5mos ago
I'm starting a new personal project that will have multiple (As many as 10, possibly more) components that need to be updated every 250-500ms with updated data, all the data is pretty lightweight but with 10 components doing it I have to wonder if it'd be better to just use Laravel as an API and poll the server myself with something like axios.
For the record, my project is a PBBG (Persistent Browser-Based Game), and components will be for things like player health, stamina, currency, a list of players in the same area, etc..
"Shared Data" seems like it may be a solution since it looks like I can just write a middleware that sends the necessary data every update conditionally. Would using this be a good idea, or should I just roll my own solution?