Home > Enterprise >  Laravel does not save session after a redirect
Laravel does not save session after a redirect

Time:10-12

I am working with the TwitterOAuth Framework from Abraham to get login via a twitter account to my web app.

I first save the token_secret in the session with the global laravel session helper and then redirect the user to the authorization page on twitter, like this:

session(['token_secret' => $requestToken['oauth_token_secret']]);
return Redirect()->away($url);

Before the redirect, the token_secret is saved in the session as expected, but when twitter redirects back to my site, its not. I check it like this:

dd(session()->all());

It worked with the PHP Session Handling but I decided to use the laravel session helper instead. My Routes are like this:

Route::group(['middleware' => 'web'], function () {
    Route::prefix('/twitter')->group(function () {
        Route::get('/authenticate', [TwitterController::class, 'authenticate'])->name('twitter_authenticate');
        Route::get('/saveCredentials', [TwitterController::class, 'saveCredentials'])->name('twitter_saveCredentials');
    });
});

Does anyone know how I can fix this?

Thanks!

CodePudding user response:

Thanks for you answer! I already tried it, its not working either.

For me, it feels like I need to reassign the session to the user, the file for the session still exists in my project with the expected token.

Is there a way to give the user his session back after a redirect?

CodePudding user response:

you can use redirect and with and automatically laravel send data to another route.

return redirect('/dashboard')->with('token_secret', $requestToken['oauth_token_secret'])
  • Related