Implement password updating and show login errors

This commit is contained in:
april
2024-01-05 17:03:39 -06:00
parent 4a0e49a959
commit 00f0def462
5 changed files with 204 additions and 76 deletions

View File

@@ -1,5 +1,6 @@
import { useApi } from "./api";
import { useNavigate } from "@remix-run/react";
import { AxiosError } from "axios";
import { createContext, useContext, useEffect, useState } from "react";
interface AuthContextValues {
@@ -11,7 +12,7 @@ interface AuthContextValues {
}: {
username: string;
password: string;
}) => void;
}) => Promise<string | void>;
signout: () => void;
clearUser: () => void;
}
@@ -72,9 +73,11 @@ function useProvideAuth() {
await client
.postForm("/auth/login", values)
.then((response) => handleTokens(response.data))
.catch(() => {
.catch((err: AxiosError) => {
setLoading(false);
throw new Error("Invalid username or password");
if (err.response?.status === 401)
throw new Error("Invalid username or password");
throw new Error(err.message);
});
setLoading(false);