You should never have access to .env values in the front end. All that should be handled on the server side.
Jun 9, 2022
3
Level 2
Access .env variables inside react / inertia
Hello,
I'm currently trying to access .env variables within my react props. I've managed to do this but then discovered a big security issue.
I currently add them like this to the boot function inAppServiceProvider
Inertia::share('app', [
'monthlyPayment' => env('STRIPE_PRODUCT_ID_MONTHLY'),
'yearlyPayment' => env('STRIPE_PRODUCT_ID_YEARLY'),
]);
I then get them from the app props {app.monthlyPayment} but I noticed with the react chrome extension I can see them. Not sure if this would be the case in production? It doesn't really matter for these but if I needed to access sensitive data then it would be an issue.
Please or to participate in this conversation.