This part covers the how to send email for password reset and email verification as like parse.com’s earlier feature, but using your own hosted parse server. This tutorial assumes you have already hosted your parse server and your app is working fine using Heroku & mLab as parse server and database.
Hope you have already installed and deployed Heroku CLI on your system, if not, follow below steps. same steps are listed under your deploy option in the heroku app.
Install the Heroku Toolbelt
Download and install the Heroku Toolbelt or learn more about the Heroku Command Line Interface.
$ heroku login
Clone the repository
Use Git to clone app’s source code to your local machine.
$ heroku git:clone -a your-app-name $ cd appsstudio
Deploy your changes
Make some changes to the code you just cloned and deploy them to Heroku using Git.
$ git add . $ git commit -am "make it better" $ git push heroku master
Usually you may get error like below .
fatal: 'heroku' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
And solution for that is connecting your app for remote using
heroku git:remote -a your-app-name
Now you would have folder on your system with your app-name, copy required files to it, at least you need below files:
- index.js
- package.json
- create “cloud” folder — this would be used for cloud code
- create “certificates” folder – this would be used for storing push notification for iOS
Add below blue code into index.js and that would enable the password reset & email verification.
var api = new ParseServer({ databaseURI: databaseUri || 'mongodb://localhost:27017/dev', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || "Car Express", masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret! serverURL: process.env.SERVER_URL || 'https://car-express.herokuapp.com/parse', // Don't forget to change to https if needed liveQuery: { classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions }, emailAdapter: { module: 'parse-server-simple-mailgun-adapter', options: { fromAddress: process.env.EMAIL_FROM || "email-from@example.com", domain: process.env.MAILGUN_DOMAIN || "example.com", apiKey: process.env.MAILGUN_API_KEY || "API-Key", // Verification email subject verificationSubject: 'Please verify your e-mail for %appname%', // Verification email body verificationBody: 'Hi,\n\nYou are being asked to confirm the e-mail address %email% with %appname%\n\nClick here to confirm it:\n%link%', // Password reset email subject passwordResetSubject: 'Password Reset Request for %appname%', // Password reset email body passwordResetBody: 'Hi,\n\nYou requested a password reset for %appname%.\n\nClick here to reset it:\n%link%', //OPTIONAL (will send HTML version of email): passwordResetBodyHTML: "<!--DOCTYPE html>........" } } });
If you have Mailgun account, add below config variables under Settings –> Reveal Configs Vars
- EMAIL_FROM — info@example.com
- MAILGUN_API_KEY — key-xxxxxxx (get from your mailgun account)
- MAILGUN_DOMAIN — example.com
- MAILGUN_PUBLIC_KEY — public-xxxx (get from your mailgun account)
- MAILGUN_SMTP_LOGIN — usually postmaster@your-domain.com
- MAILGUN_SMTP_PASSWORD — xxxxxxxxxx (default STMP password)
You’re all set with setup for password reset and email verification functionality, you can start using these features just like on parse.com
I’ve recently did migration for my apps which were hosted on the Parse.com, so thought to put all steps together here for different parts of the migrations. Parse itself has great documentation on Github, with some minor changes, you should be able to use that documentation. Here I’m covering the parts which may be questions for newbies who don’t know much about Node.js or overall backend and any issues I came across during migration. I would be covering below topics either in this blog or subsequent blogs.