mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
fix auth for email actions in MFA scenarios
This commit is contained in:
@ -201,7 +201,7 @@ export function handleMfaLogin(
|
|||||||
location: Location<any>,
|
location: Location<any>,
|
||||||
values: { code: string }
|
values: { code: string }
|
||||||
) {
|
) {
|
||||||
const { session, setToken } = useUserState.getState();
|
const { session, setToken, setSession } = useUserState.getState();
|
||||||
|
|
||||||
api
|
api
|
||||||
.post(
|
.post(
|
||||||
@ -212,6 +212,7 @@ export function handleMfaLogin(
|
|||||||
{ headers: { 'X-Session-Token': session } }
|
{ headers: { 'X-Session-Token': session } }
|
||||||
)
|
)
|
||||||
.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);
|
||||||
});
|
});
|
||||||
|
@ -99,11 +99,15 @@ export function SecurityContent() {
|
|||||||
function EmailContent() {
|
function EmailContent() {
|
||||||
const [value, setValue] = useState<string>('');
|
const [value, setValue] = useState<string>('');
|
||||||
const [newEmailValue, setNewEmailValue] = useState('');
|
const [newEmailValue, setNewEmailValue] = useState('');
|
||||||
const [user] = useUserState((state) => [state.user]);
|
const [session] = useUserState((state) => [state.session]);
|
||||||
const { isLoading, data, refetch } = useQuery({
|
const { isLoading, data, refetch } = useQuery({
|
||||||
queryKey: ['emails'],
|
queryKey: ['emails'],
|
||||||
queryFn: () =>
|
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(
|
function runServerAction(
|
||||||
@ -122,7 +126,11 @@ function EmailContent() {
|
|||||||
act = api.delete;
|
act = api.delete;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
act(apiUrl(url), { email: value })
|
act(
|
||||||
|
apiUrl(url),
|
||||||
|
{ email: value },
|
||||||
|
{ headers: { 'X-Session-Token': session } }
|
||||||
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
refetch();
|
refetch();
|
||||||
})
|
})
|
||||||
@ -131,9 +139,13 @@ function EmailContent() {
|
|||||||
|
|
||||||
function addEmail() {
|
function addEmail() {
|
||||||
api
|
api
|
||||||
.post(apiUrl(ApiEndpoints.user_emails), {
|
.post(
|
||||||
email: newEmailValue
|
apiUrl(ApiEndpoints.user_emails),
|
||||||
})
|
{
|
||||||
|
email: newEmailValue
|
||||||
|
},
|
||||||
|
{ headers: { 'X-Session-Token': session } }
|
||||||
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
refetch();
|
refetch();
|
||||||
})
|
})
|
||||||
@ -142,10 +154,14 @@ function EmailContent() {
|
|||||||
|
|
||||||
function changePrimary() {
|
function changePrimary() {
|
||||||
api
|
api
|
||||||
.post(apiUrl(ApiEndpoints.user_emails), {
|
.post(
|
||||||
email: value,
|
apiUrl(ApiEndpoints.user_emails),
|
||||||
primary: true
|
{
|
||||||
})
|
email: value,
|
||||||
|
primary: true
|
||||||
|
},
|
||||||
|
{ headers: { 'X-Session-Token': session } }
|
||||||
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
refetch();
|
refetch();
|
||||||
})
|
})
|
||||||
@ -157,40 +173,46 @@ function EmailContent() {
|
|||||||
return (
|
return (
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={6}>
|
<Grid.Col span={6}>
|
||||||
<Radio.Group
|
{data.length == 0 ? (
|
||||||
value={value}
|
<Text>
|
||||||
onChange={setValue}
|
<Trans>Currently no emails are registered</Trans>
|
||||||
name='email_accounts'
|
</Text>
|
||||||
label={t`The following email addresses are associated with your account:`}
|
) : (
|
||||||
>
|
<Radio.Group
|
||||||
<Stack mt='xs'>
|
value={value}
|
||||||
{data.map((email: any) => (
|
onChange={setValue}
|
||||||
<Radio
|
name='email_accounts'
|
||||||
key={email.id}
|
label={t`The following email addresses are associated with your account:`}
|
||||||
value={String(email.id)}
|
>
|
||||||
label={
|
<Stack mt='xs'>
|
||||||
<Group justify='space-between'>
|
{data.map((email: any) => (
|
||||||
{email.email}
|
<Radio
|
||||||
{email.primary && (
|
key={email.email}
|
||||||
<Badge color='blue'>
|
value={String(email.email)}
|
||||||
<Trans>Primary</Trans>
|
label={
|
||||||
</Badge>
|
<Group justify='space-between'>
|
||||||
)}
|
{email.email}
|
||||||
{email.verified ? (
|
{email.primary && (
|
||||||
<Badge color='green'>
|
<Badge color='blue'>
|
||||||
<Trans>Verified</Trans>
|
<Trans>Primary</Trans>
|
||||||
</Badge>
|
</Badge>
|
||||||
) : (
|
)}
|
||||||
<Badge color='yellow'>
|
{email.verified ? (
|
||||||
<Trans>Unverified</Trans>
|
<Badge color='green'>
|
||||||
</Badge>
|
<Trans>Verified</Trans>
|
||||||
)}
|
</Badge>
|
||||||
</Group>
|
) : (
|
||||||
}
|
<Badge color='yellow'>
|
||||||
/>
|
<Trans>Unverified</Trans>
|
||||||
))}
|
</Badge>
|
||||||
</Stack>
|
)}
|
||||||
</Radio.Group>
|
</Group>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</Radio.Group>
|
||||||
|
)}
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={6}>
|
<Grid.Col span={6}>
|
||||||
<Stack>
|
<Stack>
|
||||||
|
Reference in New Issue
Block a user