GithubHelp home page GithubHelp logo

Comments (6)

opheliadesign avatar opheliadesign commented on May 18, 2024 1

Ugh apparently I either had an idiot moment or just missed a step, the middleware line was missing. All better now :)

from laravel-caffeine.

mikebronner avatar mikebronner commented on May 18, 2024

I was wondering if this might happen. I wonder if the session is not getting refreshed in your instance. (All my routes are hitting the Session middleware, which is critical. If the route doesn't hit that, then that's the issue.)

Can you post your kernel.php and routes.php here for me, and let me know which routes your AJAX is hitting?

from laravel-caffeine.

olimorris avatar olimorris commented on May 18, 2024

Sure.

My Kernal.php file looks like:

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware::class
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web'  => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class
        ],
        'home' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class
        ],
        'api'  => [
            'throttle:60,1'
        ]
    ];
    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth'              => \App\Http\Middleware\Authenticate::class,
        'auth.basic'        => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest'             => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle'          => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'auth.organisation' => \App\Http\Middleware\OrganisationAccessOnly::class,
        'auth.interim' => \App\Http\Middleware\InterimAccessOnly::class
    ];
}

and my routes.php file is:

<?php

Route::group(['middleware' => ['web']], function () {

    // This is the current route the app is on.
    Route::get('/jobs/{slug}', [
        'as' => 'viewjob',
        'middleware' => 'auth',
        'uses' => 'JobController@show'
    ]);

    // This is the route that is hit via the a post request.
    Route::post('/shortlist/add/{bidId}', [
        'as' => 'addtoshortlist',
        'middleware' => 'auth.organisation',
        'uses' => 'ShortlistController@store'
    ]);

}

and with vue.js I'm making a call like this:

        /*
         * Add a bid to a shortlist.
         */
        shortlistBid: function(bidId) {
            var self = this;

            this.shortlistingBid = bidId;

            this.$http.post('/shortlist/add/' + bidId)
                .success(function() {
                    this.getBids();
                    this.shortlistingBid = false;
                });
        },

The issue must be with the refreshing of the tokens in my view. Somehow it's not taking place.

from laravel-caffeine.

opheliadesign avatar opheliadesign commented on May 18, 2024

Laravel 5.2 project, same overall issue here. I have Caffeine installed as instructed in the docs, it does appear to be working at all anymore. Receiving TokenMismatchException errors for the login form and Ajax pages throughout the project. Here is my CSRF token meta:

<meta name="csrf-token" id="csrf-token" content="{{ csrf_token() }}">

I am also using VueJS, same settings as olimorris. Composer line:

"genealabs/laravel-caffeine": "^0.3.8",

from laravel-caffeine.

olimorris avatar olimorris commented on May 18, 2024

@mikebronner I owe you an apology! I was using this on my dev machine and Laravel DebugBar always seems to these errors:

XMLHttpRequest cannot load http://myproject.dev/_debugbar/open?op=get&id=7993e14d3edd1828e4b3d1be9e39939b. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access

Now when I use BarryVDH's Cors package, these errors stop and Laravel Caffeine works.

@opheliadesign can you see if you're having the exact same issues then I think this issue can be closed!

from laravel-caffeine.

mikebronner avatar mikebronner commented on May 18, 2024

Ah, that's good to know! I will add a note to the README.

from laravel-caffeine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.