Skip to content

Commit 5cded9f

Browse files
committed
Use POST action for logout links
1 parent ac770b8 commit 5cded9f

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

frontend/js/behaviors/logoutButton.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// POST logout action
2+
3+
const logoutButton = function () {
4+
const logoutForm = document.querySelector('[data-logout-form]')
5+
6+
if (!logoutForm) return
7+
8+
document.body.addEventListener('click', e => {
9+
if (e.target.hasAttribute('data-logout-btn')) {
10+
e.preventDefault()
11+
logoutForm.submit()
12+
}
13+
})
14+
}
15+
16+
export default logoutButton

frontend/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import 'styles/app.scss'
44
import Vue from 'vue'
55
import navToggle from '@/behaviors/navToggle'
66
import showEnvLine from '@/behaviors/showEnvLine'
7+
import logoutButton from '@/behaviors/logoutButton'
78
import search from '@/main-search'
89
import merge from 'lodash/merge'
910

1011
const A17Init = function () {
1112
navToggle()
1213
showEnvLine()
14+
logoutButton()
1315
}
1416

1517
// User header dropdown

routes/auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if (config('twill.enabled.users-management')) {
66
Route::get('login', 'LoginController@showLoginForm')->name('login.form');
77
Route::post('login', 'LoginController@login')->name('login');
8-
Route::get('logout', 'LoginController@logout')->name('logout');
8+
Route::post('logout', 'LoginController@logout')->name('logout');
99

1010
Route::get('password/reset', 'ForgotPasswordController@showLinkRequestForm')->name('password.reset.link');
1111
Route::post('password/email', 'ForgotPasswordController@sendResetLinkEmail')->name('password.reset.email');

views/layouts/main.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
@include('twill::partials.footer')
7272
</section>
7373
</div>
74+
75+
<form class="visually-hidden" method="POST" action="{{ route('admin.logout') }}" data-logout-form>
76+
@csrf
77+
</form>
78+
7479
<script>
7580
window['{{ config('twill.js_namespace') }}'] = {};
7681
window['{{ config('twill.js_namespace') }}'].version = '{{ config('twill.version') }}';

views/partials/navigation/_overlay_navigation.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@if(isset($currentUser))
2323
<a href="{{ route('admin.users.index') }}">{{ twillTrans('twill::lang.nav.cms-users') }}</a><br />
2424
<a href="{{ route('admin.users.edit', $currentUser->id) }}">{{ twillTrans('twill::lang.nav.settings') }}</a><br />
25-
<a href="{{ route('admin.logout') }}">{{ twillTrans('twill::lang.nav.logout') }}</a>
25+
<a href="#" data-logout-btn>{{ twillTrans('twill::lang.nav.logout') }}</a>
2626
@endif
2727
</div>
2828
</div>

views/partials/navigation/_user.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a href="{{ route('admin.users.index') }}">{{ twillTrans('twill::lang.nav.cms-users') }}</a>
1515
@endcan
1616
<a href="{{ route('admin.users.edit', $currentUser->id) }}">{{ twillTrans('twill::lang.nav.settings') }}</a>
17-
<a href="{{ route('admin.logout') }}">{{ twillTrans('twill::lang.nav.logout') }}</a>
17+
<a href="#" data-logout-btn>{{ twillTrans('twill::lang.nav.logout') }}</a>
1818
</div>
1919
</a17-dropdown>
2020
@endif

0 commit comments

Comments
 (0)