# Error: Amity SDK (400100): The argument 'encoding' is invalid for data of length 9. Received 'hex'

**URL:** <https://forum.social.plus/t/error-amity-sdk-400100-the-argument-encoding-is-invalid-for-data-of-length-9-received-hex/967>\
**Category:** TS SDK\
**Created:** [October 31, 2023, 7:22am UTC](https://forum.social.plus/t/error-amity-sdk-400100-the-argument-encoding-is-invalid-for-data-of-length-9-received-hex/967 "2023-10-31T07:22:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jethaniya\_20](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jethaniya\_20](https://forum.social.plus/u/jethaniya_20)\
**Post date:** [October 31, 2023, 7:22am UTC](https://forum.social.plus/t/error-amity-sdk-400100-the-argument-encoding-is-invalid-for-data-of-length-9-received-hex/967/1 "2023-10-31T07:22:57Z")

</div>

![Screenshot from 2023-10-31 12-48-51](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/ca2a93bc59e9ccf5ed978a7bd769bea518b777a0.png)  
getting this error while trying to log in user to the Amity platform following is the code of the file:-

import { isServer } from ‘@/constants/index’;  
import { useRootStore } from ‘@/providers/RootStoreProvider’;  
import { useUser } from ‘@auth0/nextjs-auth0/client’;  
import { useRouter } from ‘next/router’;  
import { useEffect } from ‘react’;  
import useSWR from ‘swr’;  
import { User } from ‘@/types/User’;  
import { fetcher } from ‘@/utils’;  
import { Client, API\_REGIONS, UserRepository } from ‘@amityco/ts-sdk’;

const client = Client.createClient(`${process.env.AMITY_API_KEY}`, API\_REGIONS.US);

const sessionHandler: Amity.SessionHandler = {  
sessionWillRenewAccessToken(renewal) {  
renewal.renew();  
},  
};

const handleConnect = (userId: string, displayName: string) =\> {  
console.log(userId, displayName);  
console.log(‘handleconnect 3’);  
return Client.login({ userId, displayName }, sessionHandler)  
.then(() =\> {  
console.log(‘handleconnect 4’);  
});  
};

function UserWatcher() {  
const rootStore = useRootStore();  
const { user: authUser, isLoading, checkSession } = useUser();  
const router = useRouter();  
useEffect(() =\> {  
if (!isServer && authUser) rootStore.initialize();  
}, [authUser]);

const { data: userData, isLoading: isLoadingUserData } = useSWR(‘/api/users/me’, fetcher);

useEffect(() =\> {  
if (!isLoadingUserData) {  
if (userData === null && !router.pathname.startsWith(‘/wizard’)) {  
router.push(‘/wizard/affiliations’);  
} else if ((userData && router.pathname.startsWith(‘/wizard’)) || router.pathname === ‘/’) {  
console.log(userData)  
console.log(userData?.email);  
console.log(‘handleconnect 1’)  
handleConnect(`${userData?.email}`, `${userData?.name}`);  
console.log(‘handleconnect 2’)  
router.push(‘/projects’);

```
  }
}

```

}, [userData, isLoadingUserData, router]);

useEffect(() =\> {  
// attempt to silently log in a authUser who has an active session on another simwin website  
(async () =\> {  
if (!authUser && !isLoading) {  
await fetch(‘/api/silent-auth’, { mode: ‘no-cors’ });  
if (checkSession) checkSession();  
}  
})();  
}, [checkSession, authUser, isLoading]);

return null;  
}

export default UserWatcher;

and here is the image of what I am getting in the console

 ![Screenshot from 2023-10-31 12-51-08](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/f622f634c7bc3bde0415e42daae5a1f72ad4b07b.png)

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [October 31, 2023, 10:49am UTC](https://forum.social.plus/t/error-amity-sdk-400100-the-argument-encoding-is-invalid-for-data-of-length-9-received-hex/967/2 "2023-10-31T10:49:58Z")

</div>

Hello, we have passed this to our team to help check, will keep you posted, thank you.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [October 31, 2023, 10:51am UTC](https://forum.social.plus/t/error-amity-sdk-400100-the-argument-encoding-is-invalid-for-data-of-length-9-received-hex/967/3 "2023-10-31T10:51:45Z")

</div>

Could you try passing apikey directly in this line: `Client.createClient(${process.env.AMITY_API_KEY}, API_[REGIONS.US](http://regions.us/));` , please?
