mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
remove x-session, not needed anymore
This commit is contained in:
@ -20,7 +20,6 @@ from django.core.validators import URLValidator
|
|||||||
from django.http import Http404, HttpResponseGone
|
from django.http import Http404, HttpResponseGone
|
||||||
|
|
||||||
import structlog
|
import structlog
|
||||||
from corsheaders.defaults import default_headers
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||||
|
|
||||||
@ -1164,8 +1163,6 @@ USE_X_FORWARDED_PORT = get_boolean_setting(
|
|||||||
# Ref: https://github.com/adamchainz/django-cors-headers
|
# Ref: https://github.com/adamchainz/django-cors-headers
|
||||||
|
|
||||||
|
|
||||||
CORS_ALLOW_HEADERS = (*default_headers, 'x-session-token')
|
|
||||||
|
|
||||||
# Extract CORS options from configuration file
|
# Extract CORS options from configuration file
|
||||||
CORS_ALLOW_ALL_ORIGINS = get_boolean_setting(
|
CORS_ALLOW_ALL_ORIGINS = get_boolean_setting(
|
||||||
'INVENTREE_CORS_ORIGIN_ALLOW_ALL', config_key='cors.allow_all', default_value=DEBUG
|
'INVENTREE_CORS_ORIGIN_ALLOW_ALL', config_key='cors.allow_all', default_value=DEBUG
|
||||||
|
@ -65,8 +65,7 @@ export const doBasicLogin = async (
|
|||||||
navigate: NavigateFunction
|
navigate: NavigateFunction
|
||||||
) => {
|
) => {
|
||||||
const { host } = useLocalState.getState();
|
const { host } = useLocalState.getState();
|
||||||
const { clearUserState, setToken, setSession, fetchUserState } =
|
const { clearUserState, setToken, fetchUserState } = useUserState.getState();
|
||||||
useUserState.getState();
|
|
||||||
|
|
||||||
if (username.length == 0 || password.length == 0) {
|
if (username.length == 0 || password.length == 0) {
|
||||||
return;
|
return;
|
||||||
@ -100,7 +99,6 @@ export const doBasicLogin = async (
|
|||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status == 200 && response.data?.meta?.is_authenticated) {
|
if (response.status == 200 && response.data?.meta?.is_authenticated) {
|
||||||
setSession(response.data.meta.session_token);
|
|
||||||
setToken(response.data.meta.access_token);
|
setToken(response.data.meta.access_token);
|
||||||
loginDone = true;
|
loginDone = true;
|
||||||
success = true;
|
success = true;
|
||||||
@ -112,7 +110,6 @@ export const doBasicLogin = async (
|
|||||||
(flow: any) => flow.id == 'mfa_authenticate'
|
(flow: any) => flow.id == 'mfa_authenticate'
|
||||||
);
|
);
|
||||||
if (mfa_flow && mfa_flow.is_pending == true) {
|
if (mfa_flow && mfa_flow.is_pending == true) {
|
||||||
setSession(err.response.data.meta.session_token);
|
|
||||||
success = true;
|
success = true;
|
||||||
navigate('/mfa');
|
navigate('/mfa');
|
||||||
}
|
}
|
||||||
@ -134,7 +131,7 @@ export const doBasicLogin = async (
|
|||||||
* @arg deleteToken: If true, delete the token from the server
|
* @arg deleteToken: If true, delete the token from the server
|
||||||
*/
|
*/
|
||||||
export const doLogout = async (navigate: NavigateFunction) => {
|
export const doLogout = async (navigate: NavigateFunction) => {
|
||||||
const { clearUserState, isLoggedIn, setSession } = useUserState.getState();
|
const { clearUserState, isLoggedIn } = useUserState.getState();
|
||||||
|
|
||||||
// Logout from the server session
|
// Logout from the server session
|
||||||
if (isLoggedIn() || !!getCsrfCookie()) {
|
if (isLoggedIn() || !!getCsrfCookie()) {
|
||||||
@ -147,7 +144,6 @@ export const doLogout = async (navigate: NavigateFunction) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setSession(undefined);
|
|
||||||
clearUserState();
|
clearUserState();
|
||||||
clearCsrfCookie();
|
clearCsrfCookie();
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
@ -205,11 +201,10 @@ export function handleMfaLogin(
|
|||||||
location: Location<any>,
|
location: Location<any>,
|
||||||
values: { code: string }
|
values: { code: string }
|
||||||
) {
|
) {
|
||||||
const { setToken, setSession } = useUserState.getState();
|
const { setToken } = useUserState.getState();
|
||||||
authApi(apiUrl(ApiEndpoints.user_login_mfa), undefined, 'post', {
|
authApi(apiUrl(ApiEndpoints.user_login_mfa), undefined, 'post', {
|
||||||
code: values.code
|
code: values.code
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
setSession(response.data.meta.session_token);
|
|
||||||
setToken(response.data.meta.access_token);
|
setToken(response.data.meta.access_token);
|
||||||
followRedirect(navigate, location?.state);
|
followRedirect(navigate, location?.state);
|
||||||
});
|
});
|
||||||
@ -323,13 +318,7 @@ export function authApi(
|
|||||||
method: 'get' | 'post' | 'put' | 'delete' = 'get',
|
method: 'get' | 'post' | 'put' | 'delete' = 'get',
|
||||||
data?: any
|
data?: any
|
||||||
) {
|
) {
|
||||||
const state = useUserState.getState();
|
|
||||||
// extend default axios instance with session token
|
|
||||||
const requestConfig = config || {};
|
const requestConfig = config || {};
|
||||||
if (!requestConfig.headers) {
|
|
||||||
requestConfig.headers = {};
|
|
||||||
}
|
|
||||||
requestConfig.headers['X-Session-Token'] = state.session;
|
|
||||||
|
|
||||||
// set method
|
// set method
|
||||||
requestConfig.method = method;
|
requestConfig.method = method;
|
||||||
|
@ -16,8 +16,6 @@ export interface UserStateProps {
|
|||||||
setUser: (newUser: UserProps) => void;
|
setUser: (newUser: UserProps) => void;
|
||||||
setToken: (newToken: string) => void;
|
setToken: (newToken: string) => void;
|
||||||
clearToken: () => void;
|
clearToken: () => void;
|
||||||
session: string | undefined;
|
|
||||||
setSession: (newSession: string | undefined) => void;
|
|
||||||
fetchUserToken: () => void;
|
fetchUserToken: () => void;
|
||||||
fetchUserState: () => void;
|
fetchUserState: () => void;
|
||||||
clearUserState: () => void;
|
clearUserState: () => void;
|
||||||
@ -53,10 +51,6 @@ export const useUserState = create<UserStateProps>((set, get) => ({
|
|||||||
set({ token: undefined });
|
set({ token: undefined });
|
||||||
setApiDefaults();
|
setApiDefaults();
|
||||||
},
|
},
|
||||||
session: undefined,
|
|
||||||
setSession: (newSession: string | undefined) => {
|
|
||||||
set({ session: newSession });
|
|
||||||
},
|
|
||||||
userId: () => {
|
userId: () => {
|
||||||
const user: UserProps = get().user as UserProps;
|
const user: UserProps = get().user as UserProps;
|
||||||
return user.pk;
|
return user.pk;
|
||||||
|
Reference in New Issue
Block a user