Skip to content

Commit

Permalink
fix(core): ensure passing onSuccess wouldn't override Refine behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadxAli committed Apr 24, 2024
1 parent 9868454 commit 165b069
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/core/src/hooks/auth/useLogin/index.ts
Expand Up @@ -136,15 +136,13 @@ export function useLogin<TVariables = {}>({
return parsed.params?.to;
}, [routerType, parsed.params, search]);

const mutation = useMutation<
AuthActionResponse,
Error | RefineError,
TVariables,
unknown
>({
const mutation = useMutation({
mutationKey: keys().auth().action("login").get(preferLegacyKeys),
mutationFn: loginFromContext,
onSuccess: async ({ success, redirectTo, error, successNotification }) => {
...(v3LegacyAuthProviderCompatible === true ? {} : mutationOptions),
onSuccess: async (data, variables, context) => {
const { success, redirectTo, error, successNotification } = data;

if (success) {
close?.("login-error");

Expand Down Expand Up @@ -176,11 +174,14 @@ export function useLogin<TVariables = {}>({
}

await invalidateAuthStore();

if (!v3LegacyAuthProviderCompatible) {
mutationOptions?.onSuccess?.(data, variables, context);
}
},
onError: (error: any) => {
open?.(buildNotification(error));
},
...(v3LegacyAuthProviderCompatible === true ? {} : mutationOptions),
meta: {
...(v3LegacyAuthProviderCompatible === true ? {} : mutationOptions?.meta),
...getXRay("useLogin", preferLegacyKeys),
Expand Down

0 comments on commit 165b069

Please sign in to comment.