diff --git a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx
index 2af1db0..15d5654 100644
--- a/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx
+++ b/nextjs-interface/src/app/ui/dashboard/ShowToken.tsx
@@ -1,11 +1,14 @@
-import React from "react";
+import React, { useEffect } from "react";
import { copyToClipboard } from "@/lib/utils";
import { useFetchToken } from "@/lib/data";
export default function ShowToken({ ip }: { ip: string }) {
const newToken = useFetchToken(ip);
- copyToClipboard(newToken);
+
+ useEffect(() => {
+ copyToClipboard(newToken);
+ }, [newToken]);
return (
diff --git a/nextjs-interface/src/lib/utils.ts b/nextjs-interface/src/lib/utils.ts
index c021972..17376b4 100644
--- a/nextjs-interface/src/lib/utils.ts
+++ b/nextjs-interface/src/lib/utils.ts
@@ -5,15 +5,20 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
+// Fonction permettant la copie du Token
export const copyToClipboard = (text: string) => {
- navigator.clipboard
- .writeText(text)
- .then(() => {
- console.log("Token copié dans le clipboard");
- })
- .catch((err) => {
- console.error("Copie du Token échoué : ", err);
- });
+ if (navigator.clipboard) {
+ navigator.clipboard
+ .writeText(text)
+ .then(() => {
+ console.log("Token copié dans le presse-papiers");
+ })
+ .catch((err) => {
+ console.error("Erreur lors de la copie du token : ", err);
+ });
+ } else {
+ console.log("Clipboard inaccessible...");
+ }
};
export function validateIp(ip: string): boolean {