|
@@ -1,19 +1,18 @@
|
|
|
"use client";
|
|
"use client";
|
|
|
import { useEffect } from 'react'
|
|
import { useEffect } from 'react'
|
|
|
import { useRouter } from 'next/navigation';
|
|
import { useRouter } from 'next/navigation';
|
|
|
-import { signOut } from "next-auth/react";
|
|
|
|
|
-import { useAppDispatch } from "@/store/hooks";
|
|
|
|
|
-import { clearCart } from "@/store/slices/cart-slice";
|
|
|
|
|
|
|
+import { emitAuthExpired } from "@/utils/auth/auth-events";
|
|
|
|
|
+
|
|
|
//https://nextjs.org/docs/app/api-reference/file-conventions/error
|
|
//https://nextjs.org/docs/app/api-reference/file-conventions/error
|
|
|
export default function Error({
|
|
export default function Error({
|
|
|
error,
|
|
error,
|
|
|
- reset
|
|
|
|
|
|
|
+ retry
|
|
|
}: {
|
|
}: {
|
|
|
- reset: () => void;
|
|
|
|
|
|
|
+ retry: () => void;
|
|
|
error: Error & { digest?: string };
|
|
error: Error & { digest?: string };
|
|
|
}) {
|
|
}) {
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
- const dispatch = useAppDispatch();
|
|
|
|
|
|
|
+
|
|
|
let msg = error.message || "There was an issue with our storefront. This could be a temporary issue, please try your action again.";
|
|
let msg = error.message || "There was an issue with our storefront. This could be a temporary issue, please try your action again.";
|
|
|
if(error.name === 'UnauthorizedError') {
|
|
if(error.name === 'UnauthorizedError') {
|
|
|
msg = "Authorization Bearer token is required. Will redirect to Login page.";
|
|
msg = "Authorization Bearer token is required. Will redirect to Login page.";
|
|
@@ -22,23 +21,12 @@ export default function Error({
|
|
|
if(error.name === 'UnauthorizedError') {
|
|
if(error.name === 'UnauthorizedError') {
|
|
|
router.push('/customer/login')
|
|
router.push('/customer/login')
|
|
|
} else {
|
|
} else {
|
|
|
- reset();
|
|
|
|
|
|
|
+ retry();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (error.name === "UnauthorizedError") {
|
|
if (error.name === "UnauthorizedError") {
|
|
|
- signOut({
|
|
|
|
|
- callbackUrl:"/customer/login",
|
|
|
|
|
- redirect: false,
|
|
|
|
|
- }).then(() => {
|
|
|
|
|
- dispatch(clearCart());
|
|
|
|
|
-
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- router.push("/customer/login");
|
|
|
|
|
- router.refresh();
|
|
|
|
|
- }, 100);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ emitAuthExpired();
|
|
|
}
|
|
}
|
|
|
// Log the error to an error reporting service
|
|
// Log the error to an error reporting service
|
|
|
console.error(error)
|
|
console.error(error)
|