I have a customer auth controller and using Sanctum for authentication
class AuthController extends Controller
{
use HttpResponses;
public function login(LoginCustomerRequest $request)
{
if (Auth::guard('customer')->attempt(['username' => $request->username, 'password' => $request->password])) {
$customer = Auth::guard('customer')->user();
$token = $customer->createToken("customer", ["customer"])->plainTextToken;
if ($customer->region_id) {
session(['region_id' => $customer->region_id]);
}
return $this->success([
'customer_id' => $customer->id,
'token' => $token,
], "Customer Logged in Successfully", 200);
}
return $this->error([], 'Invalid credentials', 401);
}
}
and I have a homepage controller that has an index method for homepage preview, it should contain products sold by the vendors around the customer according to his "region_id".
I need to tailor the result according to the region_id of logged in customer if exists, I tried using auth()->user()->region_id but it didn't work because I don't use auth middleware in this route to allow unauthenticated users to enter it.
then I used session but it didn't work also because I use API, so what's the alternative here?