0

I have built and launched all the components for the whatsapp clone tutorial. My auth server is generating valid JWT (as per jwt.io) using symetric encryption. The JWT is passed by the react-app correctly it seems since I can signup and login. Now I have some problems that I'm not able to solve right after login using the react-app.

After login, our user is redirected to components/ChatsListScreen/ChatsList.tsx. Here, we want to show data based on the connected user (using useMe()). My problem is that useMe() returns an empty object.

also I get the following error on the hasura server (running in docker):

{"timestamp":"2019-10-13T08:21:26.663+0000","level":"error","type":"http-log","detail":{"operation":{"query_execution_time":null,"user_vars":{"x-hasura-role":"user","x-hasura-user-id":"4"},"error":{"path":"$.variableValues","error":"expecting a value for non-nullable variable: userId of type: Int! in variableValues","code":"validation-failed"},"request_id":"5a8c6897-69dd-410e-bd10-f637750e1957","response_size":148,"query":{"variables":{},"operationName":"ChatsListQuery","query":"query ChatsListQuery($userId: Int!) {\n  chat(order_by: [{messages_aggregate: {max: {created_at: desc}}}]) {\n    ...chat\n    users(where: {user_id: {_neq: $userId}}) {\n      user {\n        ...user\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n\nfragment chat on chat {\n  id\n  name\n  picture\n  owner_id\n  created_at\n  messages(order_by: [{created_at: asc}]) {\n    ...message\n    __typename\n  }\n  __typename\n}\n\nfragment message on message {\n  id\n  chat_id\n  sender {\n    id\n    name\n    __typename\n  }\n  content\n  created_at\n  __typename\n}\n\nfragment user on users {\n  id\n  username\n  name\n  picture\n  __typename\n}\n"}},"http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"172.18.0.1","method":"POST"}}}

As you can see x-hasura-user-id is passed correctly, but the query expects a userId which is empty.

From my logs, and what I understand, this is caused by the fact that fetchUser that feeds the useMe() hook is empty.

Now the reason why this is empty is most probably because my hasura database is empty. The auth server database has users (the ones that signed in) but the users table from hasura is empty.

How does the users table from hasura ever gets populated?

Tbaut
  • 306
  • 1
  • 7

1 Answers1

1

This boilerplate assumes that both the auth server and Hasura APIs read and write into the same database with users table being the shared entity.

Post signup, the user is inserted into the db (users table). Here's the source on where it's happening in the Auth server.

If you have configured the auth server to write into a different database, then you need to do a sync of user data post signup.

praveenweb
  • 743
  • 4
  • 15
  • I though whole purpose of having an auth server and using JWT was to actually have a non shared DB and overall different infrastructure? So to make things work I'll probably have to change the code to use the `userId` from the JWT and in generally rely on this data for anything I do. – Tbaut Oct 14 '19 at 09:47
  • the auth server and the hasura instance do not have to share a database. But the auth server has to create JWTs which can be decrypted by the Hasura instance. Which means they use shared secret or RSA – Raul Nohea Goodness Sep 07 '21 at 20:18