diff --git a/src/frontend/src/functions/auth.tsx b/src/frontend/src/functions/auth.tsx index 60ce2d7949..b09526f2d4 100644 --- a/src/frontend/src/functions/auth.tsx +++ b/src/frontend/src/functions/auth.tsx @@ -201,7 +201,7 @@ export function handleMfaLogin( location: Location, values: { code: string } ) { - const { session, setToken } = useUserState.getState(); + const { session, setToken, setSession } = useUserState.getState(); api .post( @@ -212,6 +212,7 @@ export function handleMfaLogin( { headers: { 'X-Session-Token': session } } ) .then((response) => { + setSession(response.data.meta.session_token); setToken(response.data.meta.access_token); followRedirect(navigate, location?.state); }); diff --git a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx index 814896d8a0..09ab73141a 100644 --- a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx +++ b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx @@ -99,11 +99,15 @@ export function SecurityContent() { function EmailContent() { const [value, setValue] = useState(''); const [newEmailValue, setNewEmailValue] = useState(''); - const [user] = useUserState((state) => [state.user]); + const [session] = useUserState((state) => [state.session]); const { isLoading, data, refetch } = useQuery({ queryKey: ['emails'], queryFn: () => - api.get(apiUrl(ApiEndpoints.user_emails)).then((res) => res.data) + api + .get(apiUrl(ApiEndpoints.user_emails), { + headers: { 'X-Session-Token': session } + }) + .then((res) => res.data.data) }); function runServerAction( @@ -122,7 +126,11 @@ function EmailContent() { act = api.delete; break; } - act(apiUrl(url), { email: value }) + act( + apiUrl(url), + { email: value }, + { headers: { 'X-Session-Token': session } } + ) .then(() => { refetch(); }) @@ -131,9 +139,13 @@ function EmailContent() { function addEmail() { api - .post(apiUrl(ApiEndpoints.user_emails), { - email: newEmailValue - }) + .post( + apiUrl(ApiEndpoints.user_emails), + { + email: newEmailValue + }, + { headers: { 'X-Session-Token': session } } + ) .then(() => { refetch(); }) @@ -142,10 +154,14 @@ function EmailContent() { function changePrimary() { api - .post(apiUrl(ApiEndpoints.user_emails), { - email: value, - primary: true - }) + .post( + apiUrl(ApiEndpoints.user_emails), + { + email: value, + primary: true + }, + { headers: { 'X-Session-Token': session } } + ) .then(() => { refetch(); }) @@ -157,40 +173,46 @@ function EmailContent() { return ( - - - {data.map((email: any) => ( - - {email.email} - {email.primary && ( - - Primary - - )} - {email.verified ? ( - - Verified - - ) : ( - - Unverified - - )} - - } - /> - ))} - - + {data.length == 0 ? ( + + Currently no emails are registered + + ) : ( + + + {data.map((email: any) => ( + + {email.email} + {email.primary && ( + + Primary + + )} + {email.verified ? ( + + Verified + + ) : ( + + Unverified + + )} + + } + /> + ))} + + + )}