[PUI] Fix logout (#6284)

* fix path

* changed PUI to use logout route
Fixes #5968
This commit is contained in:
Matthias Mair 2024-01-19 00:30:19 +00:00 committed by GitHub
parent 64dbf8c1e3
commit 357f715789
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 3 deletions

View File

@ -2,7 +2,7 @@
from django.conf import settings
from django.shortcuts import redirect
from django.urls import include, path
from django.urls import include, path, re_path
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import TemplateView
@ -31,7 +31,7 @@ urlpatterns = [
spa_view,
name='password_reset_confirm',
),
path('', spa_view),
re_path('.*', spa_view),
]),
),
assets_path,

View File

@ -13,5 +13,10 @@ export function setApiDefaults() {
api.defaults.baseURL = host;
api.defaults.headers.common['Authorization'] = `Token ${token}`;
// CSRF support (needed for POST, PUT, PATCH, DELETE)
api.defaults.withCredentials = true;
api.defaults.xsrfCookieName = 'csrftoken';
api.defaults.xsrfHeaderName = 'X-CSRFToken';
}
export const queryClient = new QueryClient();

View File

@ -19,6 +19,7 @@ export enum ApiPaths {
user_email_verify = 'api-user-email-verify',
user_email_primary = 'api-user-email-primary',
user_email_remove = 'api-user-email-remove',
user_logout = 'api-user-logout',
user_list = 'api-user-list',
group_list = 'api-group-list',

View File

@ -48,7 +48,9 @@ export const doClassicLogin = async (username: string, password: string) => {
* Logout the user (invalidate auth token)
*/
export const doClassicLogout = async () => {
// TODO @matmair - logout from the server session
// Logout from the server session
await api.post(apiUrl(ApiPaths.user_logout));
// Set token in context
const { setToken } = useSessionState.getState();
setToken(undefined);

View File

@ -95,6 +95,8 @@ export function apiEndpoint(path: ApiPaths): string {
return 'auth/emails/:id/verify/';
case ApiPaths.user_email_primary:
return 'auth/emails/:id/primary/';
case ApiPaths.user_logout:
return 'auth/logout/';
case ApiPaths.currency_list:
return 'currency/exchange/';
case ApiPaths.currency_refresh: