I am currently adding Spotify Authentification to just getting the Spotify Token to have acces to different features (User Features) and for example adding to a user connected some tracks to there playlist.
Also I made the Authentification system and when I receive the User Info in my callback endpoint, Laravel (Socialite) store him in a Session file, also I can't get it from different controller like to return all genres from spotify or other things ..
My api routes (Works perfectly)
Route::prefix('/spotify')->group(function () {
Route::get('auth/redirect', function () {
return Socialite::driver('spotify')
->setScopes(SpotifyController::READ_ACCES)
->redirect();
});
Route::get('auth/callback', function () {
return response()->json(['message' => "Utilisateur connecté à spotify"]);
});
});
When I try to print user() directly into the callback, it works perfectly.
Therefore when I want to get the user token from session (registered by Laravel Socialite) in another api endpoints (For example /api/genres)
Route::prefix('genres')->group(function() {
Route::get('', [GenreController::class, 'index'])->name('genres.index');
});
class GenreController extends Controller
{
protected function index(Request $request)
{
dd(Socialite::driver('spotify')->user());
}
}
It return Invalid Exception state .. No session found ..
Any idea on how to correct this ? Does I need to store the Spotify User access token into database for each of my Connected User directly ?
My session was correctly configured
'web' => [
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
EnsureFrontendRequestsAreStateful::class,
'throttle:60,1',
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
I want to have acces to the Spotify User access token from different API endpoints, obviously I cannot get him from Session file
Thanks for your help

Socialite::driver('spotify')->user()again.