Skip to content

Commit

Permalink
Merge pull request #106 from avidreder/add-sage-dev-page
Browse files Browse the repository at this point in the history
Add sage dev page
  • Loading branch information
zach-herridge authored Nov 15, 2023
2 parents 5e231b0 + a62c80b commit c8b7ccf
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/pages/poe-stack/sage-development.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useEffect, useState } from "react";

import StyledButton from "@components/library/styled-button";
import StyledCard from "@components/library/styled-card";
import StyledInput from "@components/library/styled-input";
import PoeAccountConnectedGaurdPanel from "@components/poe-account-connected-guard-panel";
import { localStorageJwtName } from "@contexts/user-context";

export default function SageDevelopment() {
const [error, setError] = useState("");
const [isSuccess, setIsSuccess] = useState(false);
const [key, setKey] = useState(
typeof window === "undefined"
? ""
: localStorage.getItem(localStorageJwtName)
);

useEffect(() => {
async function sendKeyToDevServer() {
try {
await fetch("http://localhost:8000/auth", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
token: key,
}),
});
setIsSuccess(true);
} catch (e: unknown) {
console.log(e);
if (e instanceof Error) {
setError(e.message);
}
}
}
if (key) {
void sendKeyToDevServer();
}
}, [key]);

return (
<PoeAccountConnectedGaurdPanel>
<div>
<StyledCard title={"Auth Key"}>
<div className="font-bold">
Syncing auth with your local PoeStack Sage
</div>
{isSuccess && (
<div className="font-bold text-green-600">Syncing successful!</div>
)}
{error && <div className="text-red-600">Error: {error}</div>}
</StyledCard>
</div>
</PoeAccountConnectedGaurdPanel>
);
}

0 comments on commit c8b7ccf

Please sign in to comment.