Back

Disabling services

  • 0
  • Self Hosted
  • General
  • Web
Faye
4 May, 2024, 21:41

Hey,

So, you can disabled services. It also says this: When disabled, the services are not accessible to client SDKs but remain accessible to server SDKs.

Now when trying to do for example:

TypeScript
'use client'

import { useEffect } from 'react'
import { setOrgId } from '@/utils/actions/system/setOrgId'

export default function OrgChecks({ defaultOrgId }) {
  useEffect(() => {
    const setOrgIdIfNotPresent = async () => {
      if (!defaultOrgId) {
        await setOrgId()
      }
    }
    setOrgIdIfNotPresent().then()
  }, [defaultOrgId])

  return null
}

Where the setOrgId:

TypeScript
'use server'
import { createSessionServerClient } from '@/app/appwrite-session'
import { cookies } from 'next/headers'

export async function setOrgId() {
  const { teams } = await createSessionServerClient()
  const teamsData = await teams.list().catch((error) => {
    return error
  })

  console.log(teamsData)

  cookies().set(`orgId`, teamsData.teams[0].$id, {
    httpOnly: false,
    secure: true,
    sameSite: 'Lax',
    //maxAge: new Date(session.expire),
    path: '/',
    domain: process.env.NEXT_PUBLIC_COOKIE_DOMAIN,
  })

  return teamsData
}

And the createSessionServerClient:

TypeScript
import { Teams } from 'node-appwrite'
import { headers } from 'next/headers'

export async function createSessionServerClient() {
  const headersList = headers()
  const cookieHeader = headersList.get('cookie')
  const cookies = cookieHeader ? cookieHeader.split('; ') : []
  const sessionCookie = cookies.find((cookie) =>
    cookie.startsWith(
      `a_session_${process.env.NEXT_PUBLIC_APPWRITE_DATABASES_PROJECT_ID}`
    )
  )
  const client = new Client()
    .setEndpoint(`${process.env.NEXT_PUBLIC_API_URL}/v1`)
    .setProject(process.env.NEXT_PUBLIC_APPWRITE_DATABASES_PROJECT_ID)

  if (sessionCookie) {
    client.setSession(sessionCookie.split('=')[1])
  }

  return {
    get teams() {
      return new Teams(client)
    },
  }
}

Now for some reason, it's saying: AppwriteException: The requested service is disabled. You can enable the service from the Appwrite console.

Why? It's still using the node-appwrite sdk yeah?

TL;DR
Developers are confused about disabling services for Server API Keys or Server SDKs. The issue arises when trying to access a service, even though it is supposedly disabled. The code snippets provided showcase the usage of the node-appwrite SDK. The error message "AppwriteException: The requested service is disabled..." suggests that the service is indeed disabled and needs to be enabled in the Appwrite console.
Faye
4 May, 2024, 21:46

I'm guessing it's talking about server API KEYS and not the node-appwrite sdk? Because then it's written incorrectly. Otherwise it has to be an issue, right? But I can't get my head around it which way it's supposed to be:

Turn off services:

  • Server API Keys only or
  • Server SDK's only
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more