#Disabling services

11 messages · Page 1 of 1 (latest)

compact ravine
#

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:

'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:

'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:

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?

#

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
spring trout
#

Services are active if you use server sdks with API keys afaik.

onyx fjord
compact ravine
#

but i don't use the api key

#

i am using the session token

#

look in the code

compact ravine
#

because the console specifically says "server sdk" and that's kind of it

onyx fjord