Skip to content

Commit 1ef585f

Browse files
committed
fix some login stuff
1 parent 3067751 commit 1ef585f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

apps/web/src/components/SignIn.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export const SignIn: React.FC = () => {
1616
const [loading, setLoading] = useState(false);
1717

1818
const handleLogin = async () => {
19-
setLoading(true);
2019
const loginResult = await login(loginForm.email, loginForm.password);
21-
setLoading(false);
2220
return loginResult;
2321
};
2422

@@ -49,6 +47,7 @@ export const SignIn: React.FC = () => {
4947
color="#FFF"
5048
marginBottom="20px"
5149
onClick={async () => {
50+
setLoading(true);
5251
try {
5352
if (!(await handleLogin())) {
5453
toaster.create({
@@ -67,6 +66,7 @@ export const SignIn: React.FC = () => {
6766
duration: 3000,
6867
});
6968
}
69+
setLoading(false);
7070
}}
7171
loading={loading}
7272
disabled={loading}

apps/web/src/context/AuthContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '../client';
2323
import { client } from '@web/client/client.gen';
2424
import { employeesControllerOnboardEmployeeMutation } from '@web/client/@tanstack/react-query.gen';
25+
import { AxiosError } from 'axios';
2526
// Reference: https://blog.finiam.com/blog/predictable-react-authentication-with-the-context-api
2627

2728
export const AuthContext = createContext<AuthContextType>(
@@ -127,6 +128,11 @@ export const AuthProvider = ({ children }: any) => {
127128
},
128129
})
129130
.then(async (response) => {
131+
if (response instanceof AxiosError) {
132+
if (response.response?.status === 401) {
133+
throw new Error('Invalid email or password');
134+
}
135+
}
130136
if (response.data == null) {
131137
return false;
132138
}

0 commit comments

Comments
 (0)