Closed circlefind closed 5 years ago
did you run artisan migrate --seed
to create and fill the tables?
Yes and all success
c:\xampp\htdocs\ApiApDK>php artisan migrate:fresh --seed Dropped all tables successfully. Migration table created successfully. Migrating: 2018_01_01_000000_create_permission_tables Migrated: 2018_01_01_000000_create_permission_tables Migrating: 2018_03_03_232931_create_users_table Migrated: 2018_03_03_232931_create_users_table Migrating: 2018_03_03_232948_create_password_resets_table Migrated: 2018_03_03_232948_create_password_resets_table Seeding: RolesSeeder Database seeding completed successfully.
make sure you are sending a json header and a valid json body payload with user credentials
In DevTools: Response Headers Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE Access-Control-Allow-Origin: * Access-Control-Max-Age: 86400 Cache-Control: no-cache, private Connection: close Content-Type: application/json Date: Sat, 23 Mar 2019 02:09:27 +0700, Fri, 22 Mar 2019 19:09:27 GMT Host: 127.0.0.1:8000 Server-Timing: app; dur=311.18607521057; desc="Application", db; dur=6.65; desc="Database", timeline-event-total; dur=311.31315231323; desc="Total execution time." X-Clockwork-Id: 1553281767-0569-1594999140 X-Clockwork-Version: 2.3 X-Powered-By: PHP/7.2.12
Request Headers Provisional headers are shown Accept: application/json, text/plain, / Accept-Language: en-us Content-Type: application/json;charset=UTF-8 Origin: http://localhost:8080 Referer: http://localhost:8080/ User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
May is CORS is blocked where Request Header with Provisional headers are shown?
Try php artisan key:generate
and then php artisan migrate:refresh
@stefanvanherwijnen good point!
Thanks @mstaack and @stefanvanherwijnen for respon Sorry for asking a lot I'm interest for use this boilerplate api lumen and quasar starter for my project
Still same If i register new user with quasar-api-starter @stefanvanherwijnen this success inserted but if i login still failed. and show "message": "Email address or password is incorrect."
Its trouble in Auth::attempt($credentials); ?
You need to verify the user before you can login. If the email settings are correct you should receive an email. You can also use
$user = App\User::where('email', -yourEmail-)->first();
$user->verify();
I try this : public function login(LoginRequest $request) { $email = $request->get('email'); $user = User::where('email', $email )->first();
$credentials = $request->only('email', 'password');
$token = Auth::attempt($credentials);
if (!$token) {
return response()->json(['message' => $user], 401);
}
return response()->json(['data' => ['user' => Auth::user(), 'token' => $token]]);
}
And result data found and token still empty
{"message":{"id":1,"name":"John Doe","email":"demo@demo.com","created_at":"2019-03-24 12:21:37","updated_at":"2019-03-24 12:21:37","roleNames":["administrator"]}}
Thanks @stefanvanherwijnen
You are probably missing libsodium. Which php Version are you using?
@circlefind
Try to run the tests with phpunit
to see if there is a problem somewhere.
If there indeed is a problem with a package then you will have to solve that first.
Im using XAMPP for Windows 7.2.12 PHP Version 7.2.12
and enable php_sodium in php.ini extension=php_sodium
c:\xampp\htdocs\LumenApiApDK>phpunit test PHPUnit 3.7.21 by Sebastian Bergmann.
Could not use "Codedungeon\PHPUnitPrettyResultPrinter\Printer" as printer.
And still same cant login :(
your phpunit version is REALLY old
ITS WORK!!!, Update phpunit on xampp to ^7 ..
Thanks @mstaack @stefanvanherwijnen
Case Close
Can you attach postman
export for example here?
Hello, I can't login. Always I get "message": "Email address or password is incorrect." I could verify the account and everything is okey, but I can't login.
Please help me
Try modified this code in app/Extension/Authentication/PasetoAuthGuard.php
Original Code: public function attempt(array $credentials = []) { $user = $this->provider->retrieveByCredentials($credentials); if ($user && $user->verified && $this->provider->validateCredentials($user, $credentials)) { return $this->login($user); } return false; }
Modified: public function attempt(array $credentials = []) { $user = $this->provider->retrieveByCredentials($credentials); if ($user && $this->provider->validateCredentials($user, $credentials)) { return $this->login($user); } return false; }
if you can log in then the problem is at verifiied however, if you still can't log in, try checking the phpunit version or enable libsodium on php
Hi, @mstaack
I'm newbie in lumen I use lumen-api-starter with quasar-api-starter @stefanvanherwijnen try login demo@demo.com password then login_failed and i try register success but login failed
DevTools: Request URL: http://127.0.0.1:8000/auth/login Request Method: POST Status Code: 401 Unauthorized Remote Address: 127.0.0.1:8000 Referrer Policy: no-referrer-when-downgrade
Response: {"message":"Email address or password is incorrect."}
Thx before