fix(web): unrecoverable unauthorized error (#843)

fix:unauthorized error.

added check for failed login as well remove user when visiting login.

Co-authored-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2023-04-17 02:54:27 +10:00 committed by GitHub
parent 286f2f53f7
commit 0087147660
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,8 @@ import { APIClient } from "../../api/APIClient";
import { AuthContext } from "../../utils/Context"; import { AuthContext } from "../../utils/Context";
import { PasswordInput, TextInput } from "../../components/inputs/text"; import { PasswordInput, TextInput } from "../../components/inputs/text";
import { Tooltip } from "react-tooltip"; import { Tooltip } from "react-tooltip";
import Toast from "@/components/notifications/Toast";
import toast from "react-hot-toast";
type LoginFormFields = { type LoginFormFields = {
username: string; username: string;
@ -22,6 +24,12 @@ export const Login = () => {
const [, setAuthContext] = AuthContext.use(); const [, setAuthContext] = AuthContext.use();
useEffect(() => { useEffect(() => {
// remove user session when visiting login page'
APIClient.auth.logout()
.then(() => {
AuthContext.reset();
});
// Check if onboarding is available for this instance // Check if onboarding is available for this instance
// and redirect if needed // and redirect if needed
APIClient.auth.canOnboard() APIClient.auth.canOnboard()
@ -38,6 +46,11 @@ export const Login = () => {
isLoggedIn: true isLoggedIn: true
}); });
navigate("/"); navigate("/");
},
onError: () => {
toast.custom((t) => (
<Toast type="error" body="Wrong password or username!" t={t} />
));
} }
} }
); );