Use server actions instead of client-side API calls
This commit is contained in:
parent
5a3127dcb0
commit
aa453954ed
30 changed files with 703 additions and 462 deletions
23
apps/link/app/_components/CSRFProvider.tsx
Normal file
23
apps/link/app/_components/CSRFProvider.tsx
Normal 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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue