-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresetFunc.js
55 lines (43 loc) · 2.17 KB
/
resetFunc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
This function will be run when the client SDK 'callResetPasswordFunction' and is called with an object parameter
which contains four keys: 'token', 'tokenId', 'username', and 'password', and additional parameters
for each parameter passed in as part of the argument list from the SDK.
The return object must contain a 'status' key which can be empty or one of three string values:
'success', 'pending', or 'fail'
'success': the user's password is set to the passed in 'password' parameter.
'pending': the user's password is not reset and the UserPasswordAuthProviderClient 'resetPassword' function would
need to be called with the token, tokenId, and new password via an SDK. (see below)
const Realm = require("realm");
const appConfig = {
id: "my-app-id",
timeout: 1000,
app: {
name: "my-app-name",
version: "1"
}
};
let app = new Realm.App(appConfig);
let client = app.emailPasswordAuth;
await client.resetPassword(token, tokenId, newPassword);
'fail': the user's password is not reset and will not be able to log in with that password.
If an error is thrown within the function the result is the same as 'fail'.
Example below:
exports = ({ token, tokenId, username, password }, sendEmail, securityQuestionAnswer) => {
// process the reset token, tokenId, username and password
if (sendEmail) {
context.functions.execute('sendResetPasswordEmail', username, token, tokenId);
// will wait for SDK resetPassword to be called with the token and tokenId
return { status: 'pending' };
} else if (context.functions.execute('validateSecurityQuestionAnswer', username, securityQuestionAnswer)) {
// will set the users password to the password parameter
return { status: 'success' };
}
// will not reset the password
return { status: 'fail' };
};
The uncommented function below is just a placeholder and will result in failure.
*/
exports = ({ token, tokenId, username, password }) => {
// will not reset the password
return { status: 'fail' };
};