I'm just currently trying to switch from CodeIgniter to Laravel.

I have implemented the hybridouth method successful, but it seems to be only working for that route it's specified on.

I've tried searching for tutorials and examples but even they only show the auth is working on 1 route.

How can I give some function along to every route to check if a user is logged in?

Group for which the auth is needed.

Route::group(array('before' => 'auth'), function()
{
    // ALL ROUTES WITH AUTH NEEDED
});

This seems to call the normal auth and i'm using the hybridauth

Route::get('social/{action?}', array("as" => "hybridauth", function($action = "")
{
if ($action == "auth") {
    try {
        Hybrid_Endpoint::process();
    }
    catch (Exception $e) {
        return Redirect::route('hybridauth');
    }
    return;
}
try {
    $socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
    $provider = $socialAuth->authenticate("facebook");
    $userProfile = $provider->getUserProfile();
}
catch(Exception $e) {
    return $e->getMessage();
}

echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";
}));
有帮助吗?

解决方案

If you are going to run the request at every route, use a filter

App::before(function($request)
{
//check if user logged in here
});

or create filter and group your routes

Route::group(array('before' => 'auth'), function()
{

});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top