Search code examples
phplaravelvue.jssessioncookies

is there a way to have sanctum on diffrent Vue Projects


Hello I'm using Sanctum To Auth users to the system I need if someone make log in on vue project num1 he be also be logged in on vue vue project num2

I have tried to use cookie like this

       $localeCookie = Cookie::forever('locale', 'en', null, null, null, false);

                // Delete authentication-related cookies
        $response = response()->json($data, 200)->withCookie(cookie()->forget('jwt_token'));

        return  $response->withCookie(cookie('jwt_token', $token, 360));


this returns a cookie when user logs in and it's working fine in and i can see it on the first vue project but it dosent go to vue project num 2


Solution

  • Use Temporary signed URL.

    Route::get('sign', function () {
         return \Illuminate\Support\Facades\URL::temporarySignedRoute(
             'loginWithSignedUrl',
                now()->addMinutes(1),
             ['user' => 1]
         );
    })->name('sign');
    
    Route::get('loginWithSignedUrl/{user}', function (Request $request, $user) {
        if($request->hasValidSignature()) {
          auth()->loginUsingId($user);  
        } 
    })->name('loginWithSignedUrl');