I was trying to learn Outh in rust i cloned some ones git i created outh id but i was getting some error some one help me please

error
error: proc macro panicked --> src/utils/get_github_url.rs:6:1 | 6 | load_dotenv!(); | ^^^^^^^^^^^^^^ | = help: message: Failed to load .env file: Io(Custom { kind: NotFound, error: "path not found" })

error: environment variable GITHUB_OAUTH_CLIENT_ID not defined --> src/utils/get_github_url.rs:9:21 | 9 | let client_id = std::env!("GITHUB_OAUTH_CLIENT_ID"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro std::env (in Nightly builds, run with -Z macro-backtrace for more info)

error: environment variable GITHUB_OAUTH_REDIRECT_URL not defined --> src/utils/get_github_url.rs:10:24 | 10 | let redirect_uri = std::env!("GITHUB_OAUTH_REDIRECT_URL"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro std::env (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc macro panicked --> src/utils/get_google_url.rs:6:1 | 6 | load_dotenv!(); | ^^^^^^^^^^^^^^ | = help: message: Failed to load .env file: Io(Custom { kind: NotFound, error: "path not found" })

error: environment variable GOOGLE_OAUTH_CLIENT_ID not defined --> src/utils/get_google_url.rs:9:21 | 9 | let client_id = std::env!("GOOGLE_OAUTH_CLIENT_ID"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro std::env (in Nightly builds, run with -Z macro-backtrace for more info)

error: environment variable GOOGLE_OAUTH_REDIRECT_URL not defined --> src/utils/get_google_url.rs:10:24 | 10 | let redirect_uri = std::env!("GOOGLE_OAUTH_REDIRECT_URL"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro std::env (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile rust-yew-google-github-oauth2 due to 6 previous errors

you are missing a .env file, so the macro load_dotenv!() failed. you must have a .env file with the expected variable names ("GITHUB_OAUTH_CLIENT_ID" and "GITHUB_OAUTH_REDIRECT_URL" from the screenshot) as key, in order to compile this code.

please note, the load_dotenv!() and std::env!() macros are loading environment variables at compile time. I don't think it's secure to bake the credential data into the compiled binary. you probably want to use the dotenv crate and the std::env::var() function to read credentials at runtime.

3 Likes

I have created .env file but the same error

where did you put the .env file? it should be placed in the same directory as the Cargo.toml file.

also, the file must contain the required environment variable definitions, otherwise, the std::env!() macro still panics.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.