#Authorizing User Model

13 messages · Page 1 of 1 (latest)

thorny pasture
#

I provided a Bearer token, but it is still Unauthenticated.

#

is there something wrong with the code?

#

thank you

#

how can i authenticate with a bearer token before a controller action is run?

thorny pasture
#
public function login(Request $request)
{
    $validated = $request->validate([
        'email' => ['required', 'email'],
        'password' => ['required', 'min:8']
    ]);
    if (Auth::attempt($validated)) {
        $user = Auth::user();
        $user->tokens()->delete();
        $token = $user->createToken($validated['email'])->plainTextToken;
        return ['token' => $token];
    }
}
#

what about that!?

#

how does it look/feel ?!

fervent pilot
# thorny pasture what about that!?

I don’t really understand what you’re showing me? Why are you showing me a login function with username and password if you actually want to authenticate using a bearer token? 🤷‍♂️

thorny pasture
#

maybe you don't understand, because you are a little dumb? login functions with username and password are closely working together with bearer tokens. 😉

stuck herald
#

That is wrong @thorny pasture and please watch your words

#

According to Laravel, auth bearer tokens are to be used to authenticate third party applications

fervent pilot