Authorization error

Hi,

I am new to the Amity APIs and I am using @amityco/ts-sdk to develop social features in my ReactNative application.

I have a problem with fetching community posts.

This error sometime (Not Always) returns when I want to fetch:

{"error": [Error: Amity SDK (400100): Authorization info not found], "loading": false, "origin": "server"}

I am calling await connectClient({userId, displayName}); every time that user opens the app.
Also I can get user’s data by liveUser but I don’t know why I am getting the authorization error when I want to fetch community posts.

Hi Tech, before you call await connectClient({userId, displayName});, you need to initialize this code to setup AmityClient first.

import { API_REGIONS, createClient, enableCache } from '@amityco/ts-sdk';

const apiKey = 'YOUR_API_KEY';

const client = createClient(apiKey, API_REGIONS.EU);

enableCache();

For more information, you can check this link from AmityDoc https://docs.amity.co/installation#initialization

2 Likes

Thank you @aungmoehein for the response.

I have a function called connectToAmity:

export const connectToAmity = () => {
  createClient(valueConstant.amity.apiKey, API_REGIONS.US);
  enableCache();
};

I call this function in the very beginning screen of my app.

If you reread my first post, I mentioned that I can fetch community posts sometimes. It means I implemented it in the correct way.

1 Like

Hi. @Tech , did you happen to store the client object after creating the client? Can you show me the client object? There should be userId and connected status to ensure the authorization. Thank you.

2 Likes