Skip to content

Commit 0cee4be

Browse files
committed
fix: redundant double error handling in authAPI
1 parent b077575 commit 0cee4be

1 file changed

Lines changed: 12 additions & 30 deletions

File tree

resources/js/service/authAPI.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ export const getCSRF = async () => {
99
};
1010

1111
export const login = async (credentials: { email: string; password: string; remember: boolean }) => {
12-
try {
13-
await WEB.get(`/sanctum/csrf-cookie`);
14-
return API.post('/login', credentials);
15-
} catch (error) {
16-
throw error instanceof Error ? error : new Error(String(error));
17-
}
12+
await getCSRF();
13+
return API.post('/login', credentials);
1814
};
1915

2016
export function recoverAccount(credentials: { email: string }) {
@@ -26,35 +22,21 @@ export function resetPassword(credentials: { token: string; email: string; passw
2622
}
2723

2824
export const register = async (credentials: any) => {
29-
try {
30-
const response = await API.post('/register', credentials);
31-
return Promise.resolve(response);
32-
} catch (error) {
33-
throw error instanceof Error ? error : new Error(String(error));
34-
}
25+
return API.post('/register', credentials);
3526
};
3627

3728
export const logout = async () => {
38-
try {
39-
const response = await API.delete('/logout');
40-
const { data } = response;
41-
return Promise.resolve({ response: data });
42-
} catch (error) {
43-
throw error instanceof Error ? error : new Error(String(error));
44-
}
29+
const response = await API.delete('/logout');
30+
return Promise.resolve({ response: response.data });
4531
};
4632

47-
export const authenticate = async (token: string | null) => {
48-
try {
49-
return await API.get('/auth', {
50-
headers: {
51-
'X-Skip-Toast': 'true',
52-
// Authorization: `bearer ${token}`, //This is the only place i use bearer but the entire spa app uses cookies
53-
},
54-
});
55-
} catch (error) {
56-
throw error instanceof Error ? error : new Error(String(error));
57-
}
33+
export const authenticate = async () => {
34+
return API.get('/auth', {
35+
headers: {
36+
'X-Skip-Toast': 'true',
37+
// Authorization: `bearer ${token}`, //This is the only place i use bearer but the entire spa app uses cookies
38+
},
39+
});
5840
};
5941

6042
export function changePassword(data: ChangePasswordRequest) {

0 commit comments

Comments
 (0)