Back

Not able to wrap the services in context_api πŸ˜”

  • 0
  • Web
sanujitmajhi
7 Jan, 2024, 07:07

wen i am trying to wrap the services on a provider it showing error why ???

TL;DR
The user is having trouble wrapping their services in the context_api. They are receiving an error when attempting to do so. The user included their service file code as an example. Solution: It appears that there is a typo in the code where the `Account` object is instantiated. Instead of `this.databases=new Account(this.client)`, it should be `this.databases=new Databases(this.client)`. Additionally, make sure to properly format the code using backticks for better readability.
sanujitmajhi
7 Jan, 2024, 07:07

import { Client, Databases, Account,ID} from "appwrite";

import conf from "../conf/conf";

export class Services{

TypeScript
    client = new Client()
    account
    databases

    constructor(){


        this.client.setEndpoint(conf.Appwrite_url)
        .setProject(conf.APPWRITE_PROJECT_ID)

        this.account=new Account(this.client)
        this.databases=new Account(this.client)
           
        


    }


    async register(email, password){

           try {
                  await this.account.create(email,password)
                  await this.login(email,password)

            
           } catch (error) {
                        console.log('there is some error in login')

                        return false 
         
            
           }

    }


    async login(email,password){

            try {

                await this.account.createEmailSession(email,password)
           

                
            } catch (error) {

                   console.log('there is some error in login')

                   return false 
                
            }



    }

    async logout(){

        try {
            await   this.account.deleteSessions('current')

            
        } catch (error) {

            console.log('there is some error in logout')
            
        }
        

        
    }

}

const services=new Services()

export default services here is my service file

ideclon
7 Jan, 2024, 21:58

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

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