Skip to content

Commit 3bec48d

Browse files
authored
Update users.md
Hi, this is based on my experience attempting to use the Parse GraphQL API with a custom Quasar front-end from this guide. I'm using the "customPages" feature which may be different from other users. Parse seems to be a great back-end data provider, and I'm excited to start building features with it! See also: parse-community/parse-server#7033 and parse-community/parse-server#7028 The REST Guide might benefit from the same documentation. Thank you
1 parent fa348c4 commit 3bec48d

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

_includes/graphql/users.md

+88-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ mutation logOut {
245245

246246
## Resetting Passwords
247247

248-
To use the `resetPassword` mutation your Parse Server must have an email adapter configured.
248+
To use the `resetPassword` mutation your Parse Server must have an [email adapter configured as described in the Parse Server guide](https://docs.parseplatform.org/parse-server/guide/#welcome-emails-and-email-verification).
249+
250+
When configured, this mutation will send an email with a password reset link.
249251

250252
```js
251253
// Header
@@ -272,9 +274,84 @@ mutation resetPassword {
272274
}
273275
```
274276

277+
The emailed password reset link will GET the Parse REST API to verify the token is still valid. For example:
278+
```
279+
https://www.example.com/parse/apps/APP_ID/request_password_reset?token=xxxxxxxxxxxx&username=test%40example.com
280+
```
281+
Parse will then forward the user's browser to a password reset page provided (or invalid token page) by the Parse server itself.
282+
283+
Optionally, the Parse server can be configured to forward to a custom page with-in your web application. This is done using the ["customPages" feature](https://parseplatform.org/parse-server/api/master/CustomPagesOptions.html). For example, using Express:
284+
```
285+
const parseServer = new ParseServer({
286+
// Basics: https://github.com/parse-community/parse-server#basic-options
287+
appId: process.env.PARSE_SERVER_APPLICATION_ID,
288+
...otherOptions
289+
290+
// Email: https://github.com/parse-community/parse-server#email-verification-and-password-reset
291+
verifyUserEmails: true,
292+
emailVerifyTokenValidityDuration: 2 * weekInSeconds,
293+
preventLoginWithUnverifiedEmail: false,
294+
295+
// Emailed links point to this host. It must include `/parse`
296+
publicServerURL: process.env.PARSE_PUBLIC_SERVER_URL || process.env.PARSE_SERVER_URL,
297+
// Your apps name. This will appear in the subject and body of the emails that are sent.
298+
appName: 'Application Name for User',
299+
// The email adapter
300+
emailAdapter: {
301+
module: "parse-server-aws-ses",
302+
options: {
303+
from: `Hello <${process.env.EMAIL_FROM_ADDRESS}>`,
304+
region: process.env.AWS_REGION,
305+
// aws-sdk loads keys from environment variables
306+
}
307+
},
308+
309+
customPages: {
310+
invalidLink: `${process.env.APP_PUBLIC_URL}/auth/invalid-link`,
311+
312+
verifyEmailSuccess: `${process.env.APP_PUBLIC_URL}/auth/verified`,
313+
314+
choosePassword: `${process.env.APP_PUBLIC_URL}/auth/reset-password`,
315+
passwordResetSuccess: `${process.env.APP_PUBLIC_URL}/auth/password-saved`,
316+
},
317+
318+
// account lockout policy setting (OPTIONAL) - defaults to undefined
319+
accountLockout: {
320+
duration: 5, // minutes that a locked-out account remains locked out before becoming unlocked. Set it to a value greater than 0 and less than 100000.
321+
threshold: 3, // failed sign-in attempts that will cause a user account to be locked. Set it to an integer value greater than 0 and less than 1000.
322+
},
323+
})
324+
325+
...
326+
327+
// (Required) Mounts the REST API used in email verification/password reset links.
328+
app.use('/parse', parseServer.app);
329+
330+
```
331+
332+
The Parse server forwards the browser to: `choosePassword: \`${process.env.APP_PUBLIC_URL}/auth/reset-password\`,` where your web application accepts the user's new password, and crafts a response to the server. For example, using the $axios http library.
333+
334+
```
335+
async resetPassword({ axiosClient, email, password, token }) {
336+
// Make the request
337+
await axiosClient.post(
338+
`/parse/apps/${process.env.PARSE_SERVER_APPLICATION_ID}/request_password_reset`,
339+
`username=${encodeURIComponent(email)}&new_password=${encodeURIComponent(password)}&token=${encodeURIComponent(token)}`,
340+
{
341+
headers: {
342+
'X-Requested-With': 'XMLHttpRequest',
343+
'content-type': 'application/x-www-form-urlencoded',
344+
}
345+
}
346+
)
347+
},
348+
```
349+
275350
## Send Email Verification
276351

277-
The verification email is automatically sent on sign up; this mutation is useful if the user didn't receive the first email. Again, an email adapter must be configured for this mutation to work.
352+
To use the `sendVerificationEmail` mutation your Parse Server must have an [email adapter configured as described in the Parse Server guide](https://docs.parseplatform.org/parse-server/guide/#welcome-emails-and-email-verification).
353+
354+
When configured, Parse server will automatically send emails on sign up. this mutation will re-send an email with a password reset link if the user didn't receive the first email or the token expired.
278355

279356
```js
280357
// Header
@@ -301,3 +378,12 @@ mutation sendVerificationEmail {
301378
}
302379
}
303380
```
381+
382+
The emailed verification link will GET the Parse REST API to verify the token is still valid. For example:
383+
```
384+
https://www.example.com/parse/apps/APP_ID/verify_email?token=xxxxxxxxxxxx&username=test%4example.com
385+
```
386+
387+
Parse will then process the token and forward the user's browser to verified or invalid page provided by the Parse server itself.
388+
389+
Optionally, the Parse server can be configured to forward to custom pages with-in your web application: `verifyEmailSuccess` or `customPages.invalidLink`. Please see the "Resetting Passwords" section for an example and links to further documentation.

0 commit comments

Comments
 (0)