KindeK
Kinde3y ago
28 replies
Starman

Unexpected Character Error with KindeSDK in Expo/React Native

Hi there,

I'm currently working on an Expo React Native project where I'm using the KindeSDK for authentication. I've run into an issue that I'm having trouble resolving.

Here's the relevant part of my code:

import { KindeSDK } from "@kinde-oss/react-native-sdk-0-7x";
// ...

const handleSignUp = async () => {
  try {
    const response = await client.register();
    const token = await response.json();
    if (token) {
      setIsAuthenticated(true);
      setToken(token);
    }
  } catch (error) {
    console.error("Error during sign up:", error);
  }
};

const handleSignIn = async () => {
  try {
    const response = await client.login();
    const token = await response.json();
    if (token) {
      setIsAuthenticated(true);
      setToken(token);
    }
  } catch (error) {
    console.error("Error during sign in:", error);
  }
};

// ...

const client = new KindeSDK(
  KINDE_ISSUER_URL,
  KINDE_POST_CALLBACK_URL,
  KINDE_CLIENT_ID,
  KINDE_POST_LOGOUT_REDIRECT_URL
);


When I try to sign up or sign in, I get the following error:
WARN  Possible Unhandled Promise Rejection (id: 0):
SyntaxError: JSON Parse error: Unexpected character: <
SyntaxError: JSON Parse error: Unexpected character: <


It seems like both the client.register() and client.login() methods are returning a Promise that resolves with something that's not JSON since the error is logged twice. The '<' suggests that HTML or JSX may be returned, it could also indicate that the endpoint doesn't exist. This is odd since it was working perfectly fine before, I'm not sure why that's happening or how to fix it.

I may be missing something very obvious here, but even if so I though it would make sense to post incase anyone else encounters this issue. Any help would be greatly appreciated.

Cheers!
Was this page helpful?