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:
But directly after this it is undefined:
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.
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!