Merge branch 'add-account-fix' into 'develop'
Switch account when adding another account See merge request soapbox-pub/soapbox!1935
This commit is contained in:
commit
979b7c3446
|
@ -26,23 +26,26 @@ const LoginPage = () => {
|
|||
const [mfaToken, setMfaToken] = useState(token || '');
|
||||
const [shouldRedirect, setShouldRedirect] = useState(false);
|
||||
|
||||
const getFormData = (form: HTMLFormElement) => {
|
||||
return Object.fromEntries(
|
||||
const getFormData = (form: HTMLFormElement) =>
|
||||
Object.fromEntries(
|
||||
Array.from(form).map((i: any) => [i.name, i.value]),
|
||||
);
|
||||
};
|
||||
|
||||
const handleSubmit: React.FormEventHandler = (event) => {
|
||||
const { username, password } = getFormData(event.target as HTMLFormElement);
|
||||
dispatch(logIn(username, password)).then(({ access_token }) => {
|
||||
return dispatch(verifyCredentials(access_token as string))
|
||||
dispatch(logIn(username, password))
|
||||
.then(({ access_token }) => dispatch(verifyCredentials(access_token as string)))
|
||||
// Refetch the instance for authenticated fetch
|
||||
.then(() => dispatch(fetchInstance() as any));
|
||||
}).then((account: { id: string }) => {
|
||||
.then(async (account) => {
|
||||
await dispatch(fetchInstance());
|
||||
return account;
|
||||
})
|
||||
.then((account: { id: string }) => {
|
||||
dispatch(closeModal());
|
||||
setShouldRedirect(true);
|
||||
if (typeof me === 'string') {
|
||||
dispatch(switchAccount(account.id));
|
||||
} else {
|
||||
setShouldRedirect(true);
|
||||
}
|
||||
}).catch((error: AxiosError) => {
|
||||
const data: any = error.response?.data;
|
||||
|
|
|
@ -50,14 +50,12 @@ const Header = () => {
|
|||
setLoading(true);
|
||||
|
||||
dispatch(logIn(username, password) as any)
|
||||
.then(({ access_token }: { access_token: string }) => {
|
||||
return (
|
||||
.then(({ access_token }: { access_token: string }) => (
|
||||
dispatch(verifyCredentials(access_token) as any)
|
||||
// Refetch the instance for authenticated fetch
|
||||
.then(() => dispatch(fetchInstance()))
|
||||
.then(() => setShouldRedirect(true))
|
||||
);
|
||||
})
|
||||
))
|
||||
.catch((error: AxiosError) => {
|
||||
setLoading(false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue