0

I have been stuck longer than I would like, with a problem related to email verification when creating an account on Parse-Server (/Heroku). Though I made a few post on the issue, I was not lucky enough (or maybe did not formulate things clearly enough) to get significant help. So I decided to do it all over again, this time giving a precise step by step way to reproduce the bug, for anyone interested in taking a close look. If what I do is right from start to end, then there must be a bug. If on the other hand I do something wrong (this is most probably the case), I hope somebody can point out the mistake.

Here is the process, start by creating an app on heroku, using the following commands at the terminal:

git clone https://github.com/parse-community/parse-server-example.git
mv parse-server-example linkbugapp808
cd linkbugapp808/
npm install @parse/simple-mailgun-adapter  --save
heroku create linkbugapp808

heroku addons:create mongolab:sandbox
heroku config:set APP_ID=ABCDEF-12345678:xytzt_SSTTJJZ
heroku config:set MASTER_KEY=MMMMM-87878787:wwyyssaa_PPGHYU
heroku config:set SERVER_URL=https://linkbugapp808.herokuapp.com/
heroku config:set PARSE_PUBLIC_SERVER_URL=https://linkbugapp808.herokuapp.com

Of course if the name I use "linkbugapp808" is taken or you don't like it you may choose another one.

Set the index.js file as this (fixing the mailgun parameters that need to be fixed, to fit you environment):

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var mongo = require('mongodb');
var MongoClient = mongo.MongoClient;

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri,
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID,
  masterKey: process.env.MASTER_KEY,
  serverURL: process.env.SERVER_URL,
  publicServerURL: process.env.PARSE_PUBLIC_SERVER_URL,
  appName: 'LinkBugApp',
  verifyUserEmails: true,
  emailAdapter: {
    module: '@parse/simple-mailgun-adapter',
    options: {
      fromAddress: 'from@somemail.com',
      domain: 'some.domain',
      apiKey: 'key-apiKey-mailgun-apiKey'
    }
  }
});

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a website.  Please star the parse-server repo on GitHub!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
  res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

Next run the following command in the terminal (inside the linkbugapp808 root folder):

git add . && git commit -m "update linkbugapp808" && git push heroku master

At this point the app is created on Heroku and ready to go.

Then from an iOS app create an account on the Parse-Server we just set above.

All seems to go fine.

The user for whom the account was created will receive a mail similar to this one:

Hi,

You are being asked to confirm the e-mail address usermail@xmail.com with LinkBugApp

Click here to confirm it:
https://linkbugapp808.herokuapp.com/apps/ABCDEF-12345678:xytzt_SSTTJJZ/verify_email?token=SiYyk9NgVkcwhXXWlEdEUTjyz&username=ausrnamex

When clicking the confirmation link inside the mail this is what one can see (not exactly what is expected from a sign up confirmation link):

Cannot GET /apps/ABCDEF-12345678:xytzt_SSTTJJZ/verify_email?token=SiYyk9NgVkcwhXXWlEdEUTjyz&username=ausrnamex 

I have tried with several browsers, but the result is identical.

Why do we get into this situation?

Michel
  • 10,303
  • 17
  • 82
  • 179
  • run it locally using devtools network tab in order to debug the '404' ur getting on the email response link. wild guess is it http vs https. but u should really debug it! on the cli ... 'heroku local' will run the app. For the dev DB in a test mode, u can use mongo tools or use 'parse-dashboard' to manage the new users u r creating. U R missing a step ( normal debug on localhost) by just pushing to the remote ( heroku master ) and hoping that it all works. – Robert Rowntree Mar 21 '18 at 02:52
  • try w app.use(express.static('./')) – Robert Rowntree Mar 21 '18 at 03:02
  • You may be right, but it usually works like this. And I don't really know how to use "devtools network" (though maybe I should). Running "heroku local" shows a lot of errors I had never seen before. – Michel Mar 21 '18 at 03:09
  • You mean write " app.use(express.static('./'));" instead of "app.use(express.static(__dirname + '/public'));"? Any way I tried and if I do a replacement, the user does not receive any verification mail any more. If I add a new line, the situation does not change. – Michel Mar 21 '18 at 03:59
  • heroku can be run locally, on http using a .env file located at root for the config / env vars . running locally and learning to use devtools or aapl facsimile may help u out in the long run with these type of issues. i think u are getting a simple not found on the link .. a first thing todo there is use your network debug tab in a localhost , full debug stack in order to find out why the server cant handle that url. – Robert Rowntree Mar 21 '18 at 04:16
  • OK. Where can I learn about "running heroku locally" and devtools, aapl ? Googling devtools leads me to some Chrome feature, I don't think this is what you are thinking about. – Michel Mar 21 '18 at 04:24
  • @RobertRowntree I am now digging into "running heroku locally", but how can I then simulate the creation of a user to see how things go with the email-verification? – Michel Mar 21 '18 at 10:09
  • From what I can see both your serverURL and publicServerURL are wrong, thsy should be: ``` https://linkbugapp808.herokuapp.com/parse ``` – flovilmart Mar 21 '18 at 13:27
  • @flovilmart YES! If I change both as you say to linkbugapp808.herokuapp.com/parse. It FINALLY works! Thanks a lot. What I don't understand is, I think I had tried this a zillion times before and I was getting the error: {"error":"unauthorized"}. – Michel Mar 21 '18 at 16:27

0 Answers0