From ebf08dbf2b2e6e037f21b66819b09467f4f6f1f3 Mon Sep 17 00:00:00 2001 From: Yeabsira Gashaw Date: Sun, 15 Dec 2024 22:08:55 +0300 Subject: [PATCH] implemented more auth methods to login , jwt create and change password --- src/app.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 3726040..1c396ad 100644 --- a/src/app.js +++ b/src/app.js @@ -11,6 +11,8 @@ const client = new Client() .setKey('YOUR_API_KEY'); // Replace with your API Key //.setJWT('jwt'); // Use this to authenticate with JWT generated from Client SDK +const randomEmail = `user-${Math.random().toString(36).substring(7)}@example.com`; + const databases = new Databases(client); const functions = new Functions(client); const storage = new Storage(client); @@ -21,6 +23,7 @@ let databaseId; let collectionId; let documentId; let userId; +let sessionId; let bucketId; let fileId; let functionId; @@ -365,7 +368,7 @@ const createUser = async () => { const response = await users.create( ID.unique(), - new Date().getTime() + '@example.com', + randomEmail, null, 'user@123', 'Some User' @@ -415,6 +418,38 @@ const deleteUser = async () => { console.log(response); } +const loginUsingEmailPassword = async () => { + console.log(chalk.greenBright('Running Login Using Email Password API')); + + const response = await account.createEmailPasswordSession( + randomEmail, + 'user@123' + ); + + sessionId = response.$id; + console.log(response); +} + +const createJwt = async () => { + + console.log(chalk.greenBright('Running JWT API')); + + const response = await users.createJWT(userId, sessionId); + console.log(response); +}; + +const changeUserPassword = async () => { + + console.log(chalk.greenBright('Running Change Password API')); + + const response = await users.updatePassword( + userId, + "Pass@101" + ); + + console.log(response) +}; + const createFunction = async () => { console.log(chalk.greenBright('Running Create Function API')); @@ -553,6 +588,9 @@ const runAllTasks = async () => { await listUsers(); await getUser(); await updateUserName(); + await loginUsingEmailPassword(); + await createJwt(); + await changeUserPassword(); await deleteUser(); await createFunction();