Laravel Jetstream Inertia non authorised route - laravel

I have a fairly stock install of the Laravel, jetstream inertia js setup as shown here https://jetstream.laravel.com/2.x/installation.html using command php artisan jetstream:install inertia --teams
I want to show the dashboard to non logged in users. I am using a route without the auth:sanctum', 'verified' middleware, and trying to get the controller to set up the data that the inertia stack needs to fire up when the user IS logged in:
public function getPageDashboard(){
return Inertia::render('Dashboard', [
'user' => Auth::user()
]);
}
but I'm getting a lot of errors from the front end. "Error in render: "Error: Ziggy error: 'team' parameter is required for route 'teams.show'.""
Basically sanctum? jetstream? inertia? ziggy? sets up a lot of stuff somewhere in the middleware that I have not figured out.
Any ideas on my approach here?
Edit:
Here is the web route file:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Controllers\ViewController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/dashboard', [ViewController::class, 'getPageDashboard'])->name('dashboard');

Your request will fail to overwrite user, if you want to get the authenticated user in your view you can use $page.props.user

Related

How to add custom middleware to Laravel Nova

I am not 100% expert with Laravel routes, so I am finding some issues trying to accomplish the following:
on each an every Nova page requested, I need to first verify that a token is obtained and valid on an external service (it expires every 30').
I have a controller handle managing that and working fine. My problem is that I don't hit the nail with adding this verification to a middleware.
In other words, before displaying any Nova view, I need to check that this token is not expired. If it is, I post a call and refresh it.
I've googled around and found no similar question/issue.
Anyone can give me an enlighting example?
Thanks in advance.
I found the place while looking at another post here.
What I was missing was to declare my token validator class in config/nova.php
Here:
`/*
|--------------------------------------------------------------------------
| Nova Route Middleware
|--------------------------------------------------------------------------
|
| These middleware will be assigned to every Nova route, giving you the
| chance to add your own middleware to this stack or override any of
| the existing middleware. Or, you can just stick with this stack.
|
*/
'middleware' => [
'web',
Authenticate::class,
DispatchServingNovaEvent::class,
BootTools::class,
Authorize::class,
HereShouldGoMyClass::class,
],`

Route [x] not defined when using auth middleware

I am making a website with laravel but i am getting an error while using middleware auth. it says Route[x] not defined.
i am using laravel 5.8 please some one help me
The route you have written that has no named route so you need to specify name for that route like this
Route::get('x', function() {
//
})->name('x')->middleware('auth');
for more information you can check here https://laravel.com/docs/7.x/urls#urls-for-named-routes

Laravel Passport Password Reset API route

I'm all set up with Passport in 5.5 and have the auto generated Auth\ForgotPasswordController and Auth\ResetPasswordController controllers.
However whereas /oauth/token was provided magically for me, there don't appear to be such routes for password reset when using the API.
What should my API routes look like?
Currently I've experimented with
Route::group(['prefix' => 'password'], function () {
Route::post('/email', 'Auth\ForgotPasswordController#sendResetLinkEmail');
Route::post('/reset', 'Auth\ResetPasswordController#reset');
});
but I found these in the vendor files when looking at the traits and aren't sure if this is the correct way.
The /password/email route also fails with "message": "Route [password.reset] not defined."
since you don't see any route other then 2 custom, therefore i am assumin you havn't run artisan auth command. First run that. it will add lot of routes in ur project.
Then set api driver to passport.

Moving on to next route if some url cannot be found

I am working on an application using Laravel 5.4, VueJS, AXIOS, VueRouter. VueRouter is responsible for all of the navigation in the application, save for the route config below:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/{catchall?}', ['as' => 'start', 'middleware' => 'auth', function() {
return view('home')->with([...]);
}])->where('catchall', '.*');
This essentially redirects the user to the 'base' blade file, which contains the <router-link></routerlink>.
However, I am now implementing a page in my application that anyone can access (not requiring the auth middleware), and utilizes a different layout entirely (so needs a new blade file).
Preferably, it would be accessed like this:
app.sample.com/{some-string}
Rather than something else like this:
app.sample.com/survey/{some-string}
{some-string} is a randomly generated string that is then thrown into the DB. accessible by one of my models. As I understand it, I could do something like this:
Route::get('/{some-string}', 'SomeController#somemethod')
Placing this above the catchall should work. However, in the case that /{some-string} does not match anything in the DB, I would prefer that it gets handled by the catchall, which will serve the home.blade.php
Is there any clean way to handle this?
You're essentially describing the RedirectIfAuthenticated middleware, at least thats how I would approach this. Utilize middleware to check a user's authentication level and do any route matching before serving them through to the application.

Laravel 5.2 Session not passing

I have a simple success message on store to DB.
\Session::flash('info', 'Success! Words created');
now if I var_dump the session and return that, great.
As soon as I move to another view. Session info is gone!
I've tried all sorts, I'm on laravel 5.1.
looked into the middleware groups but i just get blank pages when adding routes in here..
This is a breaking problem with the 5.2 upgrade. What's happening is the middleware which is responsible for making that errors variable available to all your views is not being utilized because it was moved from the global middleware to the web middleware group.
There are two ways to fix this:
In your kernel.php file(app/Http/Kernel.php), you can move the middleware \Illuminate\View\Middleware\ShareErrorsFromSession::class back to the protected $middleware property.
Wrap all your web routes with a route group and apply the web middleware to them:
Route::group(['middleware' => 'web'], function() {
// Place all your web routes here...(Cut all `Route` which are define in `Route file`, paste here)
});

Resources