forked from Transparency/kgroad-frontend2
added next-intl, composed next-auth and next-intl in middleware, fixed some bugs, completed details page, added google auth
This commit is contained in:
1 parent
9cd7b2a67d
commit
6637ab4eae
172 files changed
+1772
-502
No files matched your search
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { apiInstance } from "@/shared/config/apiConfig";
|
||||
import { AxiosError } from "axios";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const AuthGuard = ({ children }: { children: React.ReactNode }) => {
|
||||
const session = useSession();
|
||||
const verifyToken = async () => {
|
||||
try {
|
||||
const data = {
|
||||
token: session.data?.access_token,
|
||||
};
|
||||
await apiInstance.post("/token/verify/", data);
|
||||
} catch (error: unknown) {
|
||||
signOut({
|
||||
callbackUrl: "/",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (session.status === "loading") return;
|
||||
|
||||
verifyToken();
|
||||
}, [session.status]);
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default AuthGuard;
|
||||
Reference in new issue
Block a user