Answer the question
In order to leave comments, you need to log in
How does authorization work in laravel?
Hello everyone, I have laravel 5.8.38 - and the following question arose.
There is a standard method in the
lara which logs in the user from the controller, if I do this
Auth::login($user,true);
Auth::login($user,true);
dump(auth()->user());
return response()->json(['user' => $user], 200);
$code = $request->code;
preg_match("/(7[0-9]{10})/", $request->phone, $matches);
$phone = $matches[0];
$user = User::query()
->with('orders.items.product')
->where('phone', $phone)
->where('sms_code', $code)
->first();
$token = Str::random(60);
$token = hash('sha256', $token);
if ($user) {
// Log in current user
$user->update([
'token' => $token,
'sms_code' => null
]);
Auth::login($user,true);
return response()->json(['user' => $user], 200);
} else {
return response()
->json(['message' => 'Go away, pls'. $phone], 404)
->withCookie(cookie('token', $token, 0));
}
Answer the question
In order to leave comments, you need to log in
If the driver is session, then it is stored somewhere in the session, if the driver is different, then depending on it. Either basic authorization for each request, or tokens (for example, passport or sanctum), or you can even invent something yourself and nail it, for example, by browser ip+fingerprint
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question