@kaifusion/widget 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/widget.iife.js +72 -72
- package/package.json +1 -1
- package/src/KaiChatWidget.tsx +41 -6
package/package.json
CHANGED
package/src/KaiChatWidget.tsx
CHANGED
|
@@ -67,12 +67,34 @@ export default function KaiChatWidget({
|
|
|
67
67
|
const [userProvidedToken, setUserProvidedToken] = useState<string | null>(
|
|
68
68
|
null
|
|
69
69
|
);
|
|
70
|
+
const [isTokenValidating, setIsTokenValidating] = useState(false);
|
|
71
|
+
const [tokenError, setTokenError] = useState<string | null>(null);
|
|
70
72
|
|
|
71
73
|
const effectiveToken = authToken || userProvidedToken;
|
|
72
74
|
|
|
73
|
-
const handleTokenSubmit = (token: string) => {
|
|
74
|
-
if (token.trim())
|
|
75
|
-
|
|
75
|
+
const handleTokenSubmit = async (token: string) => {
|
|
76
|
+
if (!token.trim() || isTokenValidating) return;
|
|
77
|
+
|
|
78
|
+
setIsTokenValidating(true);
|
|
79
|
+
setTokenError(null);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const response = await fetch(`${targetUrl}/api/v1/auth/me`, {
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: `Bearer ${token}`,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (response.ok) {
|
|
89
|
+
setUserProvidedToken(token);
|
|
90
|
+
} else {
|
|
91
|
+
setTokenError("Geçersiz Erişim Anahtarı. Lütfen tekrar deneyiniz.");
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Token validation error:", error);
|
|
95
|
+
setTokenError("Bağlantı hatası. Lütfen tekrar deneyiniz.");
|
|
96
|
+
} finally {
|
|
97
|
+
setIsTokenValidating(false);
|
|
76
98
|
}
|
|
77
99
|
};
|
|
78
100
|
|
|
@@ -710,7 +732,10 @@ export default function KaiChatWidget({
|
|
|
710
732
|
<input
|
|
711
733
|
type="password"
|
|
712
734
|
placeholder="Access Token"
|
|
713
|
-
className=
|
|
735
|
+
className={`flex-1 px-4 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm text-gray-800 ${
|
|
736
|
+
tokenError ? "border-red-500" : "border-gray-300"
|
|
737
|
+
}`}
|
|
738
|
+
disabled={isTokenValidating}
|
|
714
739
|
onKeyDown={(e) => {
|
|
715
740
|
if (e.key === "Enter") {
|
|
716
741
|
handleTokenSubmit(e.currentTarget.value);
|
|
@@ -718,16 +743,26 @@ export default function KaiChatWidget({
|
|
|
718
743
|
}}
|
|
719
744
|
/>
|
|
720
745
|
<button
|
|
721
|
-
className="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 rounded-lg transition-colors text-sm"
|
|
746
|
+
className="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 rounded-lg transition-colors text-sm disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center min-w-[60px]"
|
|
747
|
+
disabled={isTokenValidating}
|
|
722
748
|
onClick={(e) => {
|
|
723
749
|
const inputEl = e.currentTarget
|
|
724
750
|
.previousElementSibling as HTMLInputElement;
|
|
725
751
|
handleTokenSubmit(inputEl.value);
|
|
726
752
|
}}
|
|
727
753
|
>
|
|
728
|
-
|
|
754
|
+
{isTokenValidating ? (
|
|
755
|
+
<Loader2 className="w-4 h-4 animate-spin" />
|
|
756
|
+
) : (
|
|
757
|
+
"Giriş"
|
|
758
|
+
)}
|
|
729
759
|
</button>
|
|
730
760
|
</div>
|
|
761
|
+
{tokenError && (
|
|
762
|
+
<p className="text-xs text-red-500 text-center">
|
|
763
|
+
{tokenError}
|
|
764
|
+
</p>
|
|
765
|
+
)}
|
|
731
766
|
</div>
|
|
732
767
|
</div>
|
|
733
768
|
)}
|