ElevenOriginal post
Web Developer
this is my auth.js:
import { Client, Account, ID } from "appwrite";
export class AuthService {
client = new Client();
account;
constructor() {
this.client
.setEndpoint(import.meta.env.VITE_APPWRITE_URL)
.setProject(import.meta.env.VITE_APPWRITE_PROJECT_ID);
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.login({ email, password });
} else {
return userAccount;
}
} catch (error) {
throw error;
}
}
async login({ 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 service :: getCurrentUser :: error", error);
}
return null;
}
async logout() {
try {
await this.account.deleteSessions();
} catch (error) {
console.log("Appwrite service :: logout :: error", error);
}
}
}
const authService = new AuthService();
export default authService
and this is how i am saving my appwrite url in the .env file:
VITE_APP_APPWRITE_URL=https://cloud.appwrite.io/v1
Please help me to fix this
Summary
Error: Uncaught TypeError when reading 'replace'. Issue is with the naming of .env variables.
Solution: Update references from 'import.meta.env.VITE_APPWRITE_URL' to 'import.meta.env.VITE_APP_APPWRITE_URL' and similarly for other variables in the 'conf' file.