I prepared an image uploader for the Summernote WYSIYWG Editor.
Basically the uploader is sending an ajax request to a certain url, this url should be protected by the AuthMiddleware from Rainlab User v3.
This here is the request from Summernote:
function uploadImage(file) {
let data = new FormData();
data.append('file', file);
$.ajax({
url: '/upload/image',
method: 'POST',
data: data,
contentType: false,
processData: false,
xhrFields: {
withCredentials: true
},
success: function(response) {
if (response.url) {
$('#summernote-editor').summernote('insertImage', response.url);
} else {
alert('Failed to upload image.');
}
},
error: function() {
alert('Error uploading image.');
}
});
Here’s my routes.php
Route::group(['middleware' => \RainLab\User\Classes\AuthMiddleware::class], function () {
trace_log("this works!");
Route::post('/upload/image', function (Request $request) {
trace_log("This code is unreachable");
return FileUploader::imageUpload($request);
});
});
I also checked the AuthMiddleware from plugins/rainlab/user/classes. The request fails at !Auth::check()
class AuthMiddleware
{
/**
* handle the request
*/
public function handle($request, Closure $next)
{
if ($jwtToken = $request->bearerToken()) {
Auth::loginUsingBearerToken($jwtToken);
}
if (!Auth::check()) {
return Response::make('Forbidden', 403);
}
return $next($request);
}
}
I use session based authentication, but I get the feeling the user data in there is not properly send. That’s why I added this here to summernote:
xhrFields: {
withCredentials: true
},
but it didnt help. Right now I am lost, any help is welcome
Thanks already ^^