Back

[SOLVED] User.$id wont export out of function

  • 0
  • Web
BloodThermic
27 May, 2023, 08:55

Why wont user.$id export outside of the handleSubmit function?

TypeScript
  import loginimg from "$lib/assets/login.jpg";
  import { Client, Account, ID } from "appwrite";
  import { goto } from "$app/navigation";
  import {PUBLIC_API_ENDPOINT, PUBLIC_PROJECT_ID} from '$env/static/public'

  const client = new Client();
  const account = new Account(client);
  
  client
  .setEndpoint(PUBLIC_API_ENDPOINT) // Your API Endpoint
  .setProject(PUBLIC_PROJECT_ID) // Your project ID
  
  let user;

  async function handleSubmit() {

  const formData = new FormData(event.target);
  const name = formData.get("name");
  const email = formData.get("email");
  const password = formData.get("password");
  
  user = await account.create(ID.unique(), email, password, name);
  
  console.log(user.$id);
}```
TL;DR
The user.$id variable is not exporting outside of the handleSubmit function. The issue is likely due to scoping. Solution: To make the user.$id variable accessible outside of the handleSubmit function, declare it outside of the function scope. For example, declare it at the top level of the file before the handleSubmit function.
Drake
27 May, 2023, 15:43

What do you mean?

BloodThermic
29 May, 2023, 00:36

[SOLVED] User.$id wont export out of function

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