TanStackT
TanStack11mo ago
7 replies
brilliant-lime

Disable refresh and first request

I want to disable the first request made, as I am using tanstack angular experimental together with ngx store, which would be based on actions, and because of that I don't want it to perform the requests when the service is injected, and the only adaptation I verified is to put an enabled: false and then modify the status.

@Injectable()
export class AuthService {
  public useAuth = injectQuery(() => ({
      queryKey: [ ...routes.common.auth.index ] as const,
      queryFn: async () => {
        return this.getAuth([ ...routes.common.auth.index ]);
      },
      
    }));
}


checkAuth$ = createEffect(() => this.actions$.pipe(
    ofType(AuthActions.checkAuth),
    switchMap(() => {
      const { isSuccess } = this.authApi.useAuth();
      this.toastr.info('Verificando autenticação...');

      if (!isSuccess) {
        return of(AuthActions.checkAuthFailure());
      }
      return of(AuthActions.checkAuthSuccess());
    }),
  ));
Was this page helpful?