Back

TypeError: Failed to construct 'URL;

  • 0
  • Web
Aasu Yadav
11 Apr, 2024, 05:14

hi i am geeting this error but the problem is that they coreectly working on localhost

but when switch to deployement and then a also change the url of web app on appwrite but getting this while authentication

here the code

API_ENDPOINT = "https://cloud.appwrite.io/v1" API_PROJECT_ID = "xxxxx" API_DATABASE_ID = "xxxxx" API_COLLECTION_ID = "xxxxx" REDIRECT_GOOGLE_AUTH = "xxxxxxx" FAILURE_ON_GOOGLE_AUTH = "xxxxxxx"

import { Client, Account, Databases, Storage } from 'appwrite';

export const client = new Client();

client .setEndpoint(${process.env.API_ENDPOINT}) .setProject(${process.env.API_PROJECT_ID});

export const account = new Account(client); export const databases = new Databases(client); export const storage = new Storage(client); export { ID } from 'appwrite';

getCurrentUser : async () => { try { console.log("db ps", process.env.API_DATABASE_ID,) const res = await account.get(); if(res){ console.log(res) set({ userData: { userStatus: res.status, userID: res.$id, userEmail: res.email, userName: res.name, }, }); } } catch (error) { console.log("error on getting current user ",error) } },

TL;DR
Developers are encountering a 'TypeError: Failed to construct 'URL'' error when switching from localhost to deployment. The URL might be incorrect after changing it in the web app settings on Appwrite. Check the URL in the code. Solution: Verify the URLs in the code, especially the API_ENDPOINT variable, after deployment. Fix any discrepancies in the URLs.
Aasu Yadav
11 Apr, 2024, 05:16

this error geeting

TypeError: Failed to construct 'URL': Invalid URL at vY.<anonymous> (index-B2QdyW3V.js:302:24618) at Generator.next (<anonymous>) at index-B2QdyW3V.js:302:17993 at new Promise (<anonymous>) at Mt (index-B2QdyW3V.js:302:17790) at vY.get (index-B2QdyW3V.js:302:24558) at getCurrentUser (index-B2QdyW3V.js:306:645) at index-B2QdyW3V.js:889:14815 at nv (index-B2QdyW3V.js:40:24283) at E0 (index-B2QdyW3V.js:40:42409)

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