Get config variables in auth0 in env file

This commit is contained in:
2021-10-04 09:59:29 -05:00
parent 737be09b5f
commit cc44c409d7
10 changed files with 58 additions and 76 deletions

View File

@@ -9,8 +9,9 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^0.20.7",
"@astrojs/renderer-react": "^0.2.1"
"@astrojs/renderer-react": "^0.2.1",
"@snowpack/plugin-dotenv": "^2.2.0",
"astro": "^0.20.7"
},
"dependencies": {
"@auth0/auth0-react": "^1.8.0"

3
site/snowpack.config.mjs Normal file
View File

@@ -0,0 +1,3 @@
export default {
plugins: [["@snowpack/plugin-dotenv", { dir: "../" }]],
};

View File

@@ -4,14 +4,15 @@ import LoginButton from "./LoginButton";
import LogoutButton from "./LogoutButton";
import Profile from "./Profile";
import ProfileFromApi from "./ProfileFromApi";
import config from "../config";
const AuthTest = () => {
return (
<Auth0Provider
domain="dev-b-bgocbi.us.auth0.com"
clientId="c5A08v815qx3ySjffHbaUc5b5MPWhRad"
domain={config.auth0.domain}
clientId={config.auth0.clientId}
redirectUri={window.location.origin}
audience="https://1t8da6s66e.execute-api.us-east-1.amazonaws.com/"
audience={config.auth0.audience}
scope="read:stuff"
>
<LoginButton />

View File

@@ -7,14 +7,14 @@ const ProfileFromApi = () => {
useEffect(() => {
const getMessage = async () => {
try {
const accessToken = await getAccessTokenSilently({
audience: "https://1t8da6s66e.execute-api.us-east-1.amazonaws.com/",
scope: "read:stuff",
});
const authorizedUrl = "https://1t8da6s66e.execute-api.us-east-1.amazonaws.com/authorized";
const authorizedUrl =
"https://1t8da6s66e.execute-api.us-east-1.amazonaws.com/authorized";
const authorizedResponse = await fetch(authorizedUrl, {
headers: {
@@ -40,11 +40,7 @@ const ProfileFromApi = () => {
<h2>{user.name}</h2>
<p>{user.email}</p>
<h3>API Message</h3>
{message ? (
<pre>{message}</pre>
) : (
"No message found"
)}
{message ? <pre>{message}</pre> : "No message found"}
</div>
)
);

View File

@@ -13,6 +13,14 @@ config.domains = {};
* This will enable your front-end to communicate with your back-end.
* (e.g. 'https://api.mydomain.com' or 'https://091jafsl10.execute-api.us-east-1.amazonaws.com')
*/
config.domains.api = "https://1t8da6s66e.execute-api.us-east-1.amazonaws.com";
config.domains.api = `https://${import.meta.env.SNOWPACK_PUBLIC_API_DOMAIN}`;
/**
* Auth0 config values
*/
config.auth0 = {};
config.auth0.domain = import.meta.env.SNOWPACK_PUBLIC_AUTH0_DOMAIN;
config.auth0.clientId = import.meta.env.SNOWPACK_PUBLIC_AUTH0_CLIENT_ID;
config.auth0.audience = `https://${import.meta.env.SNOWPACK_PUBLIC_API_DOMAIN}/`;
export default config;

View File

@@ -14,6 +14,7 @@ let title = 'My Astro Site';
// Full Astro Component Syntax:
// https://docs.astro.build/core-concepts/astro-components/
---
<html lang="en">
<head>