jadjoubran / laravel5-angular-material-starter

Get started with Laravel 5.3 and AngularJS (material)
https://laravel-angular.readme.io/
MIT License
1.66k stars 401 forks source link

have a problem with authecation #479

Closed harmon1ca closed 7 years ago

harmon1ca commented 7 years ago

I have a problem with login form. Got a 500 error on enter(api/auth/login 500 error(anonymous function)).But if i use wrong password i get 401 AuthController.php i get 401 error(anonymous function).

public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required|email',
            'password' => 'required|min:8',
        ]);

        $credentials = $request->only('email', 'password');

        try {
            // verify the credentials and create a token for the user
            if (! $token = JWTAuth::attempt($credentials)) {
                return response()->error('Invalid credentials', 401);
            }
        } catch (\JWTException $e) {
            return response()->error('Could not create token', 500);
        }

        $user = Auth::user();

        return response()->success(compact('user', 'token'));

i update composer.json to "tymon/jwt-auth": "1.0.*@dev" and it not helped Centos 6.7

jadjoubran commented 7 years ago

Hi @harmon1ca Do you have use Auth; at the top of your file?

harmon1ca commented 7 years ago

I have this in AuthController.php

namespace App\Http\Controllers\Auth;

use Auth;
use JWTAuth;
use Tymon\JWTAuth\Providers\JWT;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

but i commented "try catch" in AuthController.php

$credentials = $request->only('email', 'password');

        /*try {
            // verify the credentials and create a token for the user
            if (! $token = JWTAuth::attempt($credentials)) {
                return response()->error('Invalid credentials', 401);
            }
        } catch (\JWTException $e) {
            return response()->error('Could not create token', 500);
        }*/

        $user = Auth::user();

and get warning "Expecting a token named "data.token". In network tab i saw 233

jadjoubran commented 7 years ago

Alright then you need to check the logs in this file: storage/logs/laravel.log It will give you a pointer on why it's returning a 500

harmon1ca commented 7 years ago

I check log, last notice was "2017-03-10 08:26:28"

[2017-03-10 08:26:28] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found' in /vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:146
Stack trace:
#0 {main}  

and i corected it

harmon1ca commented 7 years ago

i have progress with this problem. I change /app/User.php add "implements JWTSubject" and getJWTIdentifier(),getJWTCustomClaims() And it work(request 200 without errors) scree But after logged not redirect to my auth page

asinan007 commented 7 years ago

Hi, little new to this. I just pulled the latest, and was reading the docs. On JWT Auth Section under Overview it does say there will be an auto generated LoginController.php but unfortunately it is not there. Am i missing something here??