extended-salmon
extended-salmon4mo ago

Live provider issue

I followed the information on this doc https://refine.dev/docs/advanced-tutorials/real-time, to set up an Ably live provider and it doesn't work. I have my data provider and auth provider working fine, but as soon as I add the live provider my app component stops rendering, it just shows a blank page with a <noscript>You need to enable JavaScript to run this app.</noscript> I attached two images showing both related files. Like I said, that code you see on the app renders a blank page, but if I were to comment the live provider line it would work just fine.
No description
No description
5 Replies
kapa.ai
kapa.ai4mo ago
Hi @JonFckinSnow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- It sounds like there might be an issue with how the liveProvider is being integrated into your application. Let's go through the steps to ensure everything is set up correctly. Steps to Set Up Ably Live Provider 1. Install the Ably Live Provider Package: Make sure you have installed the @refinedev/ably package.
npm install @refinedev/ably

npm install @refinedev/ably

2. Create the Ably Client: Create a file src/utility/ablyClient.ts and define your Ably API key.
import { Ably } from "@refinedev/ably";

export const ablyClient = new Ably.Realtime("your-api-key");

import { Ably } from "@refinedev/ably";

export const ablyClient = new Ably.Realtime("your-api-key");

3. Integrate the Live Provider in Your App: Update your App.tsx to include the liveProvider from @refinedev/ably.
import { Refine } from "@refinedev/core";
import { useNotificationProvider, Layout } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";
import { liveProvider } from "@refinedev/ably";
import { ablyClient } from "utility/ablyClient"; // Ensure the correct path is used

import "@refinedev/antd/dist/reset.css";

import { PostList, PostCreate, PostEdit, PostShow } from "pages/posts";
import { Header } from "./components/header";
import { useTranslation } from "react-i18next";

function App() {
const { t, i18n } = useTranslation();

const i18nProvider = {
translate: (key: string, params: object) => t(key, params),
changeLocale: (lang: string) => i18n.changeLanguage(lang),
getLocale: () => i18n.language,
};

return (
<Refine
routerProvider={routerProvider}
notificationProvider={useNotificationProvider}
Layout={Layout}
i18nProvider={i18nProvider}
dataProvider={dataProvider("<https://api.fake-rest.refine.dev">)}
Header={Header}
liveProvider={liveProvider(ablyClient)}
options={{ liveMode: "auto" }}
resources={[
{
name: "posts",
list: PostList,
create: PostCreate,
edit: PostEdit,
show: PostShow,
},
]}
/>
);
}

export default App;

import { Refine } from "@refinedev/core";
import { useNotificationProvider, Layout } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";
import { liveProvider } from "@refinedev/ably";
import { ablyClient } from "utility/ablyClient"; // Ensure the correct path is used

import "@refinedev/antd/dist/reset.css";

import { PostList, PostCreate, PostEdit, PostShow } from "pages/posts";
import { Header } from "./components/header";
import { useTranslation } from "react-i18next";

function App() {
const { t, i18n } = useTranslation();

const i18nProvider = {
translate: (key: string, params: object) => t(key, params),
changeLocale: (lang: string) => i18n.changeLanguage(lang),
getLocale: () => i18n.language,
};

return (
<Refine
routerProvider={routerProvider}
notificationProvider={useNotificationProvider}
Layout={Layout}
i18nProvider={i18nProvider}
dataProvider={dataProvider("<https://api.fake-rest.refine.dev">)}
Header={Header}
liveProvider={liveProvider(ablyClient)}
options={{ liveMode: "auto" }}
resources={[
{
name: "posts",
list: PostList,
create: PostCreate,
edit: PostEdit,
show: PostShow,
},
]}
/>
);
}

export default App;

Troubleshooting 1. Check the API Key: Ensure that the API key you are using is correct and has the necessary permissions. 2. Console Errors: Open the browser's developer console to check for any errors that might give more insight into why the app is not rendering. 3. Dependencies: Ensure all necessary dependencies are installed and up-to-date. 4. Example Code: You can refer to the example provided by Refine to compare your setup: - View Source Code (https://github.com/refinedev/refine/tree/master/examples/live-provider-ably) - Run on your local (https://refine.dev/docs/advanced-tutorials/real-time/#example) ```bash npm create refine-app@latest -- --example live ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@709555396292902953> kapa.ai is still learning and improving, please let us know how it did by reacting below
extended-salmon
extended-salmonOP4mo ago
I already validated my apikey multiple times, the one I'm using has full permissions so it's definitely not a permission issue. I also already verified the example you guys have and did everything exactly the same but it's still not working
fascinating-indigo
fascinating-indigo4mo ago
Can you show console errors? It might be that you are missing something on the ably side.
extended-salmon
extended-salmonOP4mo ago
Hey, I solved it, I'll document it here so that if someone else encounters the issue they can solve it too: It turns out it was my mistake and it was related to my .env file from which I was getting my api key. I'm used to working with Nodejs so I used my regular "process.env." syntax, but since this is React and I'm using Vite with refine, I had to add the "VITE_" prefix to my key, and instead of process.env I had to use import.meta.env (see attached image)
No description