Way to Tell Whether Published App is Running in Expo Client

Please provide the following:

  1. SDK Version: 38.0.4
  2. Platforms(Android/iOS/web/all): all

I am trying to set up redirect URLs for an auth flow using AWS Cognito and WeBroswer.openAuthSessionAsync. I need to return one of three different redirect URLs depending on the environment the app is running in. I using the following code to attempt to do that:

const getRedirect = (): string => {
  const appOwnerShip: "expo" | "standalone" | "guest" = Constants.appOwnership;

  // development
  if (appOwnerShip === "expo") {
    return "exp://192.168.0.25:19000/";
  }
  // Published app in standalone: myapp://
  if (appOwnerShip === "standalone") {
    return "project-avacodo://";
  }
  // Published app in Expo client: exp://exp.host/@community/with-webbrowser-redirect
  // This does not work
  return "exp://exp.host/@reggie3/project-avacodo/";
};

However, apps run in the Expo client have an appOwnerShip of “expo” whether they are run as a Published Project or from the “Recently In Development” menu in the client. Is there some way to tell the programmatically tell the difference?

You likely can detect it from Linking.getInitialURL(), I confirm that it’s exp://exp.host/... for published project. Also, __DEV__ will naturally be true for development but this is changeable.

2 Likes

@subus That looks like it works. Thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.