Back

getCurrentUser :: invalidURL

  • 0
  • Databases
  • Auth
  • Web
  • Cloud
chiranjeev
28 Jun, 2024, 07:06

while implementing login signup functionality using appwrite I am getting invalid URL error in appwrite. I am also attaching the ss of it below for reference. It will be of great help if someone can help me debug this

TL;DR
The developer posted code for an AuthService class that includes methods for account creation, login, getting the current user, and logout using Appwrite. The issue mentioned is about an "invalid URL" error. They are looking for help debugging this error.
be4st
28 Jun, 2024, 07:13

can u post the code here in text?

chiranjeev
28 Jun, 2024, 07:19

yes sure

chiranjeev
28 Jun, 2024, 07:19

import conf from "../conf/conf.js"; import { Client, Account, ID } from "appwrite";

export class AuthService{ client=new Client(); account; constructor(){ this.client.setEndpoint(conf.appwriteUrl). setProject(conf.appwriteProjectId) this.account=new Account(this.client) }

async createAccount({email,password,name}){ try{ const userAccount=await this.account.create(ID.unique(),email,password,name) if(userAccount){ return this.loginAccount({email,password}) } else{ return userAccount } } catch(error){ throw error } } async loginAccount({email,password}){ try{ return await this.account.createEmailPasswordSession(email,password); } catch(error){ throw error } } async getCurrentUser(){ try{ return await this.account.get() } catch(error){ console.log("Appwrite servce :: getCurrentUser():: ",error) } return null } async logout(){ try{ return await this.account.deleteSessions(); } catch(error){ console.log("Appwrite servce :: logout():: ",error) } }

};

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

// const client = new Client() // .setEndpoint('https://cloud.appwrite.io/v1') // .setProject('<PROJECT_ID>');

// const account = new Account(client);

const AuthServiceObj=new AuthService() export default AuthServiceObj;

chiranjeev
28 Jun, 2024, 07:19

this is the code of the Auth file

be4st
28 Jun, 2024, 07:27

@chiranjeev pls use three backticks to format and post

chiranjeev
28 Jun, 2024, 07:31

ok sir

chiranjeev
28 Jun, 2024, 07:31
TypeScript
import conf from "../conf/conf.js";
import { Client, Account, ID } from "appwrite";

export class AuthService{
client=new Client();
account;
constructor(){
this.client.setEndpoint(conf.appwriteUrl).
setProject(conf.appwriteProjectId)
this.account=new Account(this.client)
}

async createAccount({email,password,name}){
try{
const userAccount=await this.account.create(ID.unique(),email,password,name)
if(userAccount){
return this.loginAccount({email,password})
}
else{
return userAccount
}
}
catch(error){
throw error
}
}
async loginAccount({email,password}){
try{
return await this.account.createEmailPasswordSession(email,password);
}
catch(error){
throw error
}
}
async getCurrentUser(){
try{
return await this.account.get()
}
catch(error){
console.log("Appwrite servce :: getCurrentUser():: ",error)
}
return null
}
async logout(){
try{
return await this.account.deleteSessions();
}
catch(error){
    console.log("Appwrite servce :: logout():: ",error)
}
}


};

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

// const client = new Client()
//     .setEndpoint('https://cloud.appwrite.io/v1') 
//     .setProject('<PROJECT_ID>');

// const account = new Account(client);

const AuthServiceObj=new AuthService()
export default AuthServiceObj;
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