Rank 6: Server
Heyo.
This is a continuation of #Server Action Not Working?.
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 6: Server
Heyo.
This is a continuation of #Server Action Not Working?.
Rank 6: Server
the code using appwrite.ts:
import { Client, Account, Teams, Databases, Storage, Functions, Messaging, Locale, Avatars,} from 'appwrite'
export const client = new Client() .setEndpoint(`${process.env.NEXT_PUBLIC_API_URL}/v1`) .setProject(`${process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID}`)
export const account: Account = new Account(client)export const teams: Teams = new Teams(client)export const databases: Databases = new Databases(client)export const storage: Storage = new Storage(client)export const functions: Functions = new Functions(client)export const messaging: Messaging = new Messaging(client)export const locale: Locale = new Locale(client)export const avatars: Avatars = new Avatars(client)
export { ExecutionMethod, ID, Query } from 'appwrite'Rank 6: Server
Having a page on SSR, with a client component imported using for example this kind of code:
'use client'import { storage } from '@/app/appwrite-client'
export default function FetchGallery({ name, gallery }) { const getGalleryImageUrl = (galleryId: string) => { console.log(galleryId) if (!galleryId) return const imageId = storage.getFileView('655ca6663497d9472539', `${galleryId}`) return imageId.href }
const url = getGalleryImageUrl(gallery?.galleryId) console.log(url)
// The rest of the component remains unchanged with conditional rendering based on the data's availability. return ( <img src={url} alt={name || 'Image'} className={`imgsinglegallery mx-auto h-[400px] w-auto max-w-full rounded-lg object-contain`} /> )}Will spam "window is not defined" every time you refresh the page.
example of mine:
//database.jsx
import { account, client, database, storage, teams, userId } from "@/utils/appwrite";import { Query,ID } from "appwrite";import { publish } from "./events";
export async function GetServerSpells(IncomingFilters) { const activeFilters = IncomingFilters || []; const queryOptions = [Query.limit(850)]; if (activeFilters.length > 0) { //Include active filters in the query activeFilters.forEach((filter) => { switch (filter[0]) { case "SpellName": //console.log(`Database.jsx: Got: SpellName with filters ${filter[0]} | ${filter[1]}}`) queryOptions.push(Query.search(filter[0], `./${filter[1]}/`)); break; case "Class": queryOptions.push(Query.search(filter[0], filter[1])); break; default: queryOptions.push(Query.equal(filter[0], filter[1])); break; } }); } //console.log(`trying to find spells with filters: ${queryOptions}`); const x = await database.listDocuments( process.env.NEXT_PUBLIC_DATABASE_ID, process.env.NEXT_PUBLIC_COLLECTION_SPELL_ID, queryOptions ); const list = await SortSpells(x["documents"]); //console.log(`Database.jsx: Found list: ${JSON.stringify(list)}`); return list;}//spelllist.jsx"use client"import { useState, useEffect } from "react";import { GetServerSpells } from "@/utils/Database";
const data = async () => { setSpellData(await GetServerSpells()); }; useEffect(() => { data(); }, []);Now this is javascript but it might to the same for typescript
cause client to server is just not possible with nextjs
i think you can do the same thing with the node sdk now
Rank 6: Server
So just use a server action?
Rank 6: Server
I'll try out some stuff tomorrow.
Rank 6: Server
Does realtime work using the node sdk? 🤔
No. Please create a new post for different topics
Rank 6: Server
Well, it's still the same topic. You just wanted me to use something else.
Your original topic was using node sdk and getting window not defined. The new topic is about realtime
Rank 6: Server
Well, my issue is still about window is not defined, because I basically am not allowed to use the appwrite sdk in any way, to not get the error.
Rank 6: Server
I can try with realtime, but I figure that everything is built the same way and something in the appwrite client sdk shows that error.
So far everything else has given the error, so expected is that realtime of all things, will too.
Core
It's spamming on the server console, not the browser right?
Rank 6: Server
Both
Rank 6: Server
Core
Right. Like xmaniaxz suggested, I think you need to put calls to the @/app/appwrite-clietn inside a useEffect, that also checks window !== undefined
Core
We might be able to solve this in the SDK by not depend on window. We can do is throw a more descriptive error. Is it just the getFileView endpoint you see this with? Or all services/endpoints
Rank 6: Server
All, just make a simple createEmailPasswordSession auth page
Rank 6: Server
the moment I try to use the client sdk, basically
Core
Right, it's not easy to see where that faulty window access comes from unfortunately, but I will take some time today to track it down
Rank 6: Server
Hey!
Did you come closer towards tracking it down?