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.What do you mean?
[SOLVED] User.$id wont export out of function
Recommended threads
- I’m facing an issue with deployments on ...
Hi Appwrite Support, I’m facing an issue with deployments on Appwrite Sites. A few days ago (around 3–4 days back), everything was working perfectly. My deplo...
- Project auto-blocked after load testing ...
Hi team 👋 My project has been automatically blocked with the message: "Project is currently blocked — Access to this project is restricted. Contact support if...
- App build crashing with "Internal error"
Hello Appwrite team! 👋 We are trying to deploy a Next.js application on Appwrite Cloud, but our builds are consistently failing. The deployment log successful...