chore: moved exampled to frontend

This commit is contained in:
Felix Dubrownik
2023-03-03 14:11:13 +01:00
parent 541f94131a
commit b9fa81f76b
134 changed files with 22 additions and 40368 deletions

View File

@ -0,0 +1,31 @@
import { register } from "@teamhanko/hanko-elements";
import { useCallback, useEffect } from "react";
import { useRouter } from "next/router";
const api = process.env.NEXT_PUBLIC_HANKO_API!;
interface Props {
setError(error: Error): void;
}
function HankoAuth({ setError }: Props) {
const router = useRouter();
const redirectToTodos = useCallback(() => {
router.replace("/todo").catch(setError);
}, [router, setError]);
useEffect(() => {
register({ shadow: true }).catch(setError);
}, [setError]);
useEffect(() => {
document.addEventListener("hankoAuthSuccess", redirectToTodos);
return () =>
document.removeEventListener("hankoAuthSuccess", redirectToTodos);
}, [redirectToTodos]);
return <hanko-auth api={api} />;
}
export default HankoAuth;