Skip to content

Commit

Permalink
Update authApi.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rossen27 authored May 6, 2024
1 parent 0b5df21 commit 6fc2280
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions frontend/src/redux/api/authApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const authApi = createApi({
},
async onQueryStarted(args, { dispatch, queryFulfilled }) {
try {
await queryFulfilled;
await queryFulfilled; // 等待 query 完成
await dispatch(userApi.endpoints.getMe.initiate(null));
} catch (error) {
console.log(error);
Expand All @@ -42,8 +42,25 @@ export const authApi = createApi({
logout: builder.query({
query: () => "/logout",
}),
googleLogin: builder.mutation({
query(body) {
return {
url: "/google",
method: "POST",
body,
};
},
async onQueryStarted(args, { dispatch, queryFulfilled }) {
try {
await queryFulfilled;
await dispatch(userApi.endpoints.getMe.initiate(null));
} catch (error) {
console.log(error);
}
},
}),
}),
});

export const { useLoginMutation, useRegisterMutation, useLazyLogoutQuery } =
export const { useLoginMutation, useRegisterMutation, useLazyLogoutQuery, useGoogleLoginMutation } =
authApi;

0 comments on commit 6fc2280

Please sign in to comment.