Julien-R44/tuyau

Don't resolve the response data correctly

Closed this issue · 4 comments

I have the following route endpoint:

async login({ request, response }: HttpContext) {
    const { email, password } = await request.validateUsing(loginValidator);

    const user = await User.verifyCredentials(email, password);
    const token = await User.accessTokens.create(user);

    return response.ok({
      token,
      ...user.serialize(),
    });
  }

And use it in the frontend with Tuyau:

const signIn = async () => {
    const result = await client.user.login.$post({
      email: '',
      password: '',
    });

    const thisIsNull = result.data;
  };

Then the strange thing is that the result.data is everytime null. But somehow it looks correct in the generic, see this screenshot:
Bildschirmfoto 2024-10-26 um 17 46 59

But directly after this it is undefined:
Bildschirmfoto 2024-10-26 um 17 47 13

Do you have a idea what causes this problem?

Hey! Cannot reproduce here. Could you share a reproduction please?

Yeah, of course: https://stackblitz.com/~/github.com/jleifeld/TuyauReproductionExample

Open the the file: /apps/app/hooks/useSession.tsx and look at the result in line 34. The types there are looking correct. If you look at variable thisIsNull at line 39 you see that the data is not typed anymore and just null.

Expected is here the schema or types for the response.

Bildschirmfoto 2024-10-27 um 12 03 00 Bildschirmfoto 2024-10-27 um 12 03 03

Thanks a lot for the reproduction

Should be fixed with @tuyau/client 0.1.3. Lemme know if it works for you

It is working perfectly. Thanks for your fast response!