Add env variable

This commit is contained in:
Arthur Belleville 2025-05-04 14:39:44 +02:00
parent 72d13a54f3
commit aee1104a1b
No known key found for this signature in database
2 changed files with 17 additions and 2 deletions

1
xtablo-expo/.env Normal file
View file

@ -0,0 +1 @@
EXPO_PUBLIC_STREAM_CHAT_API_KEY="t5vvvddteapa"

View file

@ -1,4 +1,5 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { ActivityIndicator } from "react-native";
import { StreamChat } from "stream-chat";
import { Chat, OverlayProvider } from "stream-chat-expo";
@ -7,7 +8,11 @@ export default function ChatProvider({
}: {
children: React.ReactNode;
}) {
const client = StreamChat.getInstance("t5vvvddteapa");
const [isReady, setIsReady] = useState(false);
const client = StreamChat.getInstance(
process.env.EXPO_PUBLIC_STREAM_CHAT_API_KEY as string
);
useEffect(() => {
const connect = async () => {
@ -18,12 +23,21 @@ export default function ChatProvider({
},
client.devToken("artslidd")
);
setIsReady(true);
const channel = client.channel("messaging", "hello");
await channel.watch();
};
connect();
return () => {
client.disconnectUser();
setIsReady(false);
};
}, []);
if (!isReady) {
return <ActivityIndicator />;
}
return (
<OverlayProvider>
<Chat client={client}>{children}</Chat>