#Why doesn't the crate dotenv work in my Dioxus project?

1 messages · Page 1 of 1 (latest)

unique nimbus
#

Hi guys,

I would like to know if anyone had a similar problem or knows a workaround to it.

I have a Dioxus project which needs to use use variables from a .env file.

Below is the code:
extern crate dotenv;
use dioxus::{logger::tracing::info, prelude::*};
use dotenv::dotenv;
use std::env;

fn main() {
dotenv().ok();
let hidden = env::var("URL_PROJECT_SUPABASE");
match hidden {
Ok(val) => println!("hidden: {val}"),
Err(e) => println!("hidden: {e}"),
}
dioxus::launch(App);
}

fn App() -> Element {
dotenv().ok();
let hidden = env::var("URL_PROJECT_SUPABASE");
rsx! {
document::Stylesheet { href: CSS }
match hidden {
Ok(val) => rsx!(div{"hidden: {val}"}),
Err(e) => rsx!(div{"hidden: {e}"}),
}
}
}

When I try to print the variable in rust with cargo run, it successfully prints "hidden: variable_details".
However, when I run the Dioxus project with dx serve --platform web, it renders "hidden: environment variable not found
" on the web page.

How can I make the web page render the correct details from the .env file?

#

Why doesn't the crate dotenv work in my Dioxus?

#

Why doesn't the crate dotenv work in my Dioxus project?

pale nimbus
#

The website cannot access native files

#

I’m not sure what the right way of putting private details on a website is

#

Probably just having a server handle it and requesting stuff from the server