mirror of
https://github.com/koel/koel
synced 2024-11-28 15:00:42 +00:00
Auto log out when session expires (fixes #320)
This commit is contained in:
parent
68baf5001c
commit
3d46e73e8b
3 changed files with 9 additions and 8 deletions
|
@ -7,6 +7,7 @@ use App\Http\Requests\API\UserLoginRequest;
|
|||
use App\Http\Requests\API\UserStoreRequest;
|
||||
use App\Http\Requests\API\UserUpdateRequest;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Hash;
|
||||
use JWTAuth;
|
||||
use Log;
|
||||
|
@ -43,12 +44,12 @@ class UserController extends Controller
|
|||
*/
|
||||
public function logout()
|
||||
{
|
||||
try {
|
||||
JWTAuth::invalidate(JWTAuth::getToken());
|
||||
} catch (JWTException $e) {
|
||||
Log:error($e);
|
||||
|
||||
return response()->json(['error' => 'could_not_invalidate_token'], 500);
|
||||
if ($token = JWTAuth::getToken()) {
|
||||
try {
|
||||
JWTAuth::invalidate($token);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json();
|
||||
|
|
|
@ -12,6 +12,7 @@ Route::get('/♫', function () {
|
|||
Route::group(['prefix' => 'api', 'namespace' => 'API'], function () {
|
||||
|
||||
Route::post('me', 'UserController@login');
|
||||
Route::delete('me', 'UserController@logout');
|
||||
|
||||
Route::group(['middleware' => 'jwt.auth'], function () {
|
||||
Route::get('/', function () {
|
||||
|
@ -40,7 +41,6 @@ Route::group(['prefix' => 'api', 'namespace' => 'API'], function () {
|
|||
|
||||
Route::resource('user', 'UserController', ['only' => ['store', 'update', 'destroy']]);
|
||||
Route::put('me', 'UserController@updateProfile');
|
||||
Route::delete('me', 'UserController@logout');
|
||||
|
||||
Route::get('lastfm/connect', 'LastfmController@connect');
|
||||
Route::post('lastfm/session-key', 'LastfmController@setSessionKey');
|
||||
|
|
|
@ -22,7 +22,7 @@ Vue.http.interceptors.push({
|
|||
NProgress.done();
|
||||
|
||||
if (r.status === 400 || r.status === 401) {
|
||||
if (r.request.method !== 'POST' && r.request.url !== 'me') {
|
||||
if (!(r.request.method === 'POST' && r.request.url === 'me')) {
|
||||
// This is not a failed login. Log out then.
|
||||
app.logout();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue