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
- general_route_not_found - Auth Guide
If you’ve just added a subdomain to your project, verified your DNS records, and confirmed your SSL certificate is working, but you're still hitting a `general_...
- Can't resume paused project
I have logged in in incognito, done the email verification and still get the invalid fingerprint error. What's the issue.
- How to Display File in Web?
I'm trying to use Appwrite's Storage to store images and display them in my app, however when I use the `getFileView`, `getFileDownload` or `getFilePreview` met...