Skip to content

Loading env variables for both server and client? #1273

Answered by gbj
jonahlund asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah so create_resource(cx, || (), |_| async { std::env /* etc */ }) would work fine, because this will only run once, on the server, so won't panic in the browser. Remember though that this will literally send the value of the env variable as JSON to the user's browser. Don't put any secret keys in there.

Otherwise, use a server function that reads the env var and uses it, sending the result and not the env var back to the client. This keeps the env var itself secret.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@gbj
Comment options

gbj Jul 4, 2023
Maintainer

Answer selected by jonahlund
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants