React 原生动态环境暂存

问题描述

在我的登录页面上的反应应用程序中,我有环境选择组件来启用/禁用开发环境并切换到生产环境。我正在反应的 AsyncStorage 中保存标志。在登录组件中,我正在获取标志,并根据该标志选择环境以形成登录 API。但是 Asyc Storage 需要时间来获取标志并且认选择 Prod API。因此,我无法切换到开发环境。这是我的代码片段。

import APP_CONfig from "../src/services/AppConfig";
import AsyncStorage from '@react-native-community/async-storage';



const PROFILES_UI_HOST = "http://example";
const GWEB_HOST = "https://example-prod.com";
const GSANDBox = "https://example-demo.com"
 const PING_HOST_DEMO = "https://ping-demo.om";
const CREST_HOST = "http://rest-host.com";
const REDIRECT_URI = "/redirect/ouah2";
const PING_HOST = "https://ing-prod.com";

const REST_BASE_URL = "rest/v1";


  CLIENT_ID = PS_CLIENT_ID;


//problem is here for this line =>
const isDemoEnv = AsyncStorage.getItem("isDemoEnv").then(res => Boolean(res)).catch(e => false);
const G_URL = (isDemoEnv !== undefined && isDemoEnv === true) ? GSANDBox : GREENLIGHT_WEB_HOST
const PING_URL = (isDemoEnv !== undefined && isDemoEnv === true) ? PING_HOST_DEMO : PING_HOST


export const ROUTES = {
  HOST_URL_G:`${G_URL}`,BASE_URL : `${G_URL}/${REST_BASE_URL}`,HOST_URL: `${G_URL}/pr-dir-rest/services`,USERS_BASE: `https://prod.com/rest/v1/users/`,P_PROXY_BASE: `${G_URL}/p-proxy/v1`,TOS_SERVICE_BASE: `${G_URL}/legal/v1`,PING_LOGIN: `${PING_URL}/as/authorization.oauth2?response_type=code`,PING_logoUT: `${G_URL}ext/logout?response_type=code`,AUTHENTICATION_TOKEN: `${G_URL}${REST_BASE_URL}/token.oauth2`,OAUTH2_TOKEN: `${CREST_HOST}/${REST_BASE_URL}/token.oauth2`,PROFILE_PROXY_BASE: `${G_URL}/profile-proxy/v1`,};

export const getLoginUrl = () => {  
  console.log(ROUTES.PING_LOGIN + `&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}`);
return ROUTES.PING_LOGIN + `&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}`;
};

如果有人可以帮忙吗? 提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)