BloodThermicOriginal post
Rank 3: Container
Why wont user.$id export outside of the handleSubmit function?
Plain text
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);}```Summary
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.