Use server actions instead of client-side API calls

This commit is contained in:
Darren Clarke 2024-08-05 23:31:15 +02:00
parent 5a3127dcb0
commit aa453954ed
30 changed files with 703 additions and 462 deletions

View file

@ -0,0 +1,23 @@
"use client";
import { FC, PropsWithChildren, useEffect } from "react";
import { useSession } from "next-auth/react";
export const CSRFProvider: FC<PropsWithChildren> = ({ children }) => {
const { data: session, status, update } = useSession();
useEffect(() => {
const interval = setInterval(async () => {
if (status === "authenticated") {
const response = await fetch("/api/v1/users/me");
const token = response.headers.get("CSRF-Token");
update({ csrfToken: token });
console.log({ token });
}
}, 30000);
return () => clearInterval(interval);
}, [session, status, update]);
return children;
};