Back

create a cloud function to reset password

  • 0
  • Functions
Zuperman
29 Dec, 2023, 11:38

I see AppWrite includes several function samples for adding numbers and some other non-sense, but it does not include the most important samples: email verification and password reset.

I've tried every possible way to create a reset password function in appwrite, using NodeJS and i failed day after day.

Anyone knows how to do it using the Appwrite cloud functions? it would be great to have it as an example.

Also, do we need to setup the snmp and pay for "pro" to be able to verify emails on appwrite cloud?

TL;DR
The user is asking for help in creating a cloud function to reset a password using Appwrite. They mention that most Account functions require a user context and suggest using the `account.createJWT()` function to generate a JWT on the client side. They also mention the `users.updatePassword()` function in the Server SDK can be used to update a user's password. The user shares a code example that they tried, but it didn't work. They express frustration about the lack of examples for email verification and password reset in Appwrite. They also ask if setting up SNMP and upgrading to the "pro" version is necessary for email verification in App
Zuperman
29 Dec, 2023, 11:41

btw I tried this code and it didn't work. ```import { Client, Databases, Query, ID } from 'node-appwrite'; import querystring from 'node:querystring';

// This is your Appwrite function // It's executed each time we get a request export default async ({ req, res, log, error }) => { // Why not try the Appwrite SDK? // const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) .setKey(process.env.APPWRITE_API_KEY);

const account = new Account(client);

const promise = account.updateRecovery(req.query.userId, req.query.secret, 'password', 'password');

promise.then(function (response) { log(response); return res.send(response); }, function (error) { error(error); return res.send(error); });

return res.send('userid:'+req.query.userId+' secret:'+req.query.secret);```

ideclon
29 Dec, 2023, 15:26

First off, you don't seem to be importing Account

ideclon
29 Dec, 2023, 15:28

Second, I see you're using the Server SDK. In the Server SDKs, you can use users.updatePassword('[USER_ID]', 'newpassword') to update a users password

ideclon
29 Dec, 2023, 15:29

You can set whether or not a user's email address is verified with users.updateEmailVerification()

ideclon
29 Dec, 2023, 15:32

Note that most Account functions require you to be in a user context. To do this, you either need to be signed into a user (with a Client SDK), or you can generate a JWT (with account.createJWT()) on the client side, pass that to the Function and then use client.setJWT()

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