Ghimdalas
1 week ago

Exception in login

Posted 1 week ago by Ghimdalas

Hello, i try to create an API in laravel with Tymon for JWT token, i use this code:

$credentials = request(['email', 'password']);
    
    try {
        if (!$token = JWTAuth::attempt($credentials)) {
            throw new Exception('invalid_credentials');
        }
        $this->data = [
            'status' => true,
            'code' => 200,
            'data' => ['_token' => $token],
            'err' => null];
    }
    catch (Exception $e) {
        $this->data['err']['message'] = $e->getMessage();
        return response()->json($this->data, 401);
    }

but if I try it with postman (and the correct credentials) it returns me an exception (error 500) without any message (doesn't it enter the catch?)

if I try with wrong credentials, it correctly answers with "invalid_credentials"

Please sign in or create an account to participate in this conversation.