<?php

namespace App\Http\Controllers\API\Client\User;

use App\Http\Controllers\Controller;
use App\Http\Requests\API\Stock\LoginRequest;
use App\User;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;
use JWTAuth;

class IndexController extends Controller
{
    public function login(LoginRequest $request)
    {
        $credentials = [
            'email' => $request->user.'@email.com',
            'password' => $request->password
        ];

        try {
            if (!$token = JWTAuth::attempt($credentials)) {
                return response()->json('Invalid Credentials', 400);
            }
        } catch (JWTException $e) {
            return response()->json('Invalid Credentials', 500);
        }

        return response()->json(compact('token'));
    }
}
