Why doesn't the link from email verification work? - laravel

I'm using laravel jetstream with the livewire stack. In my fortify.php file this is the code. I havent changed anything, i just enabled the feature to verify the email when user signs up.
"features" => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
"confirm" => true,
"confirmPassword" => true,
// 'window' => 0,
]),
And implemented MustVerifyEmail in my User.php model like this class User extends Authenticatable implements MustVerifyEmail. ALso updated BROADCAST_DRIVER=log in .env file. When I click the link that I get in laravel.log file:
If you're having trouble clicking t=
he "Verify Email Address" button, copy and paste the URL below
into your =
web browser: [http://127.0.0.1:8000/email/verify/5/93cfe97ab6a2d5ecbbce5edf=
47197fdb28f54ad1?expires=3D1675106924&signature=3D7d26bcec33531228b2c66a419=
9fd5a15ab72ae07a1650a41213d09da00d92109](http://127.0.0.1:8000/email/verify=
/5/93cfe97ab6a2d5ecbbce5edf47197fdb28f54ad1?expires=3D1675106924&signature=
=3D7d26bcec33531228b2c66a4199fd5a15ab72ae07a1650a41213d09da00d92109)
I get not found error in my browser. This is also my web.php file:
Route::middleware(['auth:sanctum',config('jetstream.auth_session'),
'verified'
])->group(function () {
Route::get('/dashboard', function () { return view('dashboard'); })
->name('dashboard');
Route::get('/skills', function () { return view('skills'); })
->name('skills');
});
What am I doing wrong?

Related

How set uploaded avatar in this.$page.props.user with inertiajs?

In Laravel 8 app with inertiajs/inertia-vue 0.7/vuejs2 with fortify (but without jetstream)
I use "spatie/laravel-medialibrary": "^9.9" for avatar uploading like
$loggedUser = auth()->user();
$avatar_file_path = $avatarImageUploadedFile->getPathName();
$loggedUser->addMedia( $avatar_file_path )->toMediaCollection('avatar');
and it works, but in which way can I use avatar in on client part when I use
this.$page.props.user
in vue components properties to check which user is logged and show his info?
Thanks!
You can do this with the 'Shared data' feature via the HandleInertiaRequests middleware.
For example, to share user info you can do the following:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
class HandleInertiaRequests extends Middleware
{
public function share(Request $request)
{
return array_merge(parent::share($request), [
'user' => function () {
return Auth::user() ? [
'id' => Auth::user()->id,
'name' => Auth::user()->name,
'email' => Auth::user()->email,
// get path to avatar
'avatar' => Storage::url('avatar-of-the-user.jpg'),
] : null;
},
]);
}
}
Client side you can then access the avatar's URL with this.$page.props.user.avatar.

Laravel API call goes through even with session expired

I have a SPA based on Laravel 5.8 and Vue 2.0.
Everything is working fine, a little bit too much to be honest, because if I delete the session and I try to save the content afterward or keep navigating the private pages, every ajax call that I'm doing with Axios is going through without returning any error. Only if I forcefully refresh the page I get the error page I setup but if I don't, I can keep doing everything even if the session no longer exist.
This is my setup.
web.php is where I have the only php route that points to a singlePageController:
Auth::routes();
Route::get('/{any}', 'SinglePageController#index')->where('any', '.*');
Then in the singlePageController I return the view:
class SinglePageController extends Controller
{
public function index() {
return view('app', ['loggedUser' => auth()->user()]);
}
}
Then I have the api.php where I have the API routes. As you can see at the end I have the middleware to make it private. Just to make an example this is the one I use for updating the content:
Route::put('event/update/{slug}', 'EventController#update')->middleware('auth:api');
Then the related controller of that API route:
public function update(Request $request, $slug)
{
$event = Event::where('slug', $slug)->first();
$event->title = $request->input('title');
return new EventResource($event);
}
And in the end this is the Resource I use to define what and how the API data is going to be displayed:
public function toArray($request)
{
// return parent::toArray($request);
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'curator' => $this->curator,
'featured_image' => $this->featured_image,
'body' => $this->body,
'date' => $this->date
];
}
So this above is the flow I have. Then when I do an axios call to update the content, I'm doing something like:
axios({
method: 'PUT',
url: '/api/event/update/' + this.$route.params.slug + '?api_token=' + this.isLogged.apiToken,
data: dataToSave,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
.then((response) => {
this.getNotification('Success: The Event has been saved');
})
.catch((error) => {
this.getNotification('Error: Impossible saving the event');
console.log(error);
})
Thanks in advance for the help
In Laravel routes in api.php ignore the session data.
If you want to authenticate with session data you could move your api routes to web.php and you should see the results you expect.

Laravel 5.2 redirect doesn't save flash messages

I installed fresh laravel 5.2.29.
My routes.php:
Route::group(['middleware' => ['web']], function () {
Route::get('/a', function () {
return redirect('/b', 302)->with('error', 'error description');
});
Route::get('/b', function () {
return session('error');
});
});
When I go to /a in browser it redirects me to /b, but shows me nothing. What should I do to it show me error description? Or why does not it store flash data?
Basically, if you are running Laravel 5.2.27 and up, do not use the web middleware group. It is applied for you by default as you can see in app/Http/RouteServiceProvider.php:
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
});
}
If you try to apply the web middleware again, you'll run into weird problems like what you are currently facing.

Laravel socialite error 404

I followed this tutorial on how to use socialite -> https://laracasts.com/series/whats-new-in-laravel-5/episodes/9
This is what I've done:
Added to my composer.json
"laravel/socialite": "^2.0",
"laravelcollective/html": "5.1.*#dev"
Added to my app.php
providers
Laravel\Socialite\SocialiteServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
aliases
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
Added to services.php
'github' => [
'client_id' => 'myid',
'client_secret' => 'mysecret',
'redirect' => 'http://inspectorhost.app/login',
],
Added to routes.php
Route::get('/', function () {
if (Auth::check()) return 'Welcome back, ' . Auth::user()->username;
return 'Hi guest. ' . link_to('login', 'Login with Github!');
});
Route::get('login', 'AuthController#login');
Created an AuthController and added
class AuthController extends Controller
{
public function login(){
return \Socialite::with('github')->redirect();
}
}
I'm using nginx and I set it up so it doesn't need to use the public folder to acccess the web
root home/inspectorhost.app/public_html/public/;
So when I click on 'Login with Github', instead of sending me to Github to authorize the login, it sends me to /login and gives me a 404 error.
EDIT
Now it gets interesting... when I go to http://inspectorhost.app and click in 'Login with Github' I get the error from above (404) however if I run php artisan serve and I access the app from localhost:8000 it works... so I guess it might be some misconfiguration on nginx?
Any help is appreciated.
Open in private window. because after first time session store in github if your github login in other tab

Controller in subfolder with namespace in laravel-4.1

I have the following code:
Route::group(array('namespace' => 'admin'), function() {
Route::group(array('prefix' => 'admin'), function() {
Route::get('group', array('as' => 'adminGroup', 'uses' => 'GroupController#index'));
Route::get('group/index', array('as' => 'adminGroupIndex',
'uses' => 'GroupController#index'));
});
});
and controller
namespace admin;
class GroupController extends \BaseController {
protected $layout = 'dashboard';
public function index()
{
$this->layout->content = \View::make('admin/group/index');
}
}
If I point the URL to:
http://localhost/laravel/public/admin/group/index
works perfectly, but when I point to:
http://localhost/laravel/public/admin/group
does not work. It just redirects to:
http://localhost/laravel/public/user/login
But when I do not use subfolder everything works perfectly!
EDIT: SOLVED
I had started installing laravel administrator and then stopped, because there was not installed an authentication system. So I installed Sentry2 and was configuring management groups. After analyzing a little more settings Laravel Administrator, I realized that it was using the URI 'admin' and also redirected to 'user / login' if I was not authenticated.
Now everything is working perfectly!
You probably have another route filtered with "auth" that is catching that /admin/group URL and sending it to login.
I just reproduced your code here and it works fine for me. For the sake of simplicity I just replaced my routes.php file with this code:
<?php
namespace admin;
class GroupController extends \Controller {
protected $layout = 'dashboard';
public function index()
{
return 'index!';
}
}
\Route::group(array('namespace' => 'admin'), function() {
\Route::group(array('prefix' => 'admin'), function() {
\Route::get('group', array('as' => 'adminGroup', 'uses' => 'GroupController#index'));
\Route::get('group/index', array('as' => 'adminGroupIndex',
'uses' => 'GroupController#index'));
});
});
And both
http://development.consultoriodigital.net/admin/group
http://development.consultoriodigital.net/admin/group/index
Worked fine showing a page with
index!

Resources