react native - How to use environment variables in Expo - Stack Overflow

I am trying to use environment variables in my expo app.When i change my babel.config.js from:module.

I am trying to use environment variables in my expo app.

When i change my babel.config.js from:

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

to:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      ["module:react-native-dotenv", {
        "moduleName": "@env",
        "path": ".env",
        "blacklist": null,
        "whitelist": null,
        "safe": false,
        "allowUndefined": true
      }]
    ]
  };
};

And import them:

import { MY_ENV_VAR } from '@env';

Expo cannot detect that i have anything inside of app/ The docs say to prefix environment variables with EXPO_PUBLIC_ but they say: "Do not store sensitive info, such as private keys, in EXPO_PUBLIC_ variables. These variables will be visible in plain-text in your compiled application."

I want to use @supabase/supabase-js and need to store:SUPABASE_URL, SUPABASE_ANON_KEY and GOOGLE_CLIENT_ID

Is it safe to store these in EXPO_PUBLIC_ variables or is there a workaround?

I am trying to use environment variables in my expo app.

When i change my babel.config.js from:

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

to:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      ["module:react-native-dotenv", {
        "moduleName": "@env",
        "path": ".env",
        "blacklist": null,
        "whitelist": null,
        "safe": false,
        "allowUndefined": true
      }]
    ]
  };
};

And import them:

import { MY_ENV_VAR } from '@env';

Expo cannot detect that i have anything inside of app/ The docs say to prefix environment variables with EXPO_PUBLIC_ but they say: "Do not store sensitive info, such as private keys, in EXPO_PUBLIC_ variables. These variables will be visible in plain-text in your compiled application."

I want to use @supabase/supabase-js and need to store:SUPABASE_URL, SUPABASE_ANON_KEY and GOOGLE_CLIENT_ID

Is it safe to store these in EXPO_PUBLIC_ variables or is there a workaround?

Share Improve this question asked Mar 20 at 14:29 Fergus JohnsonFergus Johnson 3522 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Try restarting expo with expo r -c whenever you update .env file as variables might not be correctly loaded.

In general it is not secure to prefix variables with EXPO_PUBLIC_ as it will be embedded in the app and will be visible to anyone. However, SUPABASE_URL and SUPABASE_ANON_KEY are public by design and are safe to store in EXPO_PUBLIC_ variables. This is because Supabase has Row Level Security enabled. For GOOGLE_CLIENT_ID, it depends on its use case. It is safe if it is for OAuth login but if it's for backend authentication, use a server like cloud functions and fetch the API from there. You can check this reddit thread about using environment variables in Expo which might be helpful in your case.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744402884a4572476.html

相关推荐

  • react native - How to use environment variables in Expo - Stack Overflow

    I am trying to use environment variables in my expo app.When i change my babel.config.js from:module.

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信