このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/AuthController.php

26 行
908 B
PHP
Raw 通常表示 履歴

<?php
namespace App\Http\Controllers;
use App\Route;
use App\Legislature;
use App\Http\Controllers\Controller;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
class AuthController extends Controller {
public function authenticate(\Illuminate\Http\Request $request) {
$credentials = $request->only('username', 'password'); // grab credentials from the request
try {
if (!$token = JWTAuth::attempt($credentials)) { // attempt to verify the credentials and create a token for the user
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
return response()->json(['error' => 'could_not_create_token'], 500); // something went wrong whilst attempting to encode the token
}
return response()->json(['token' => "Bearer $token"]);
}
}
?>