codemzy / mern-auth

Full stack auth with Node, Express, Mongo and React using JWT
7 stars 2 forks source link

Cannot log in #3

Closed duongch4 closed 3 years ago

duongch4 commented 6 years ago

Hi,

Thank you very much for creating an awesome repo. I have successfully register and store data in my local MongoDB, but for some reason, I cannot log in. Info from my Mongo Compass:

_id: 5b36547af0bae467585a764e email: "test@gmail.com" password: "$2a$10$VSvAjFLCspKbFJ5TAojeCeC26GMzMdnanGi5Ms/R83eh69RLggrke" emailConfirmed: false emailConfirmCode: "1530287226872-3007-ecc"

Since no errors printed out in the terminal when I attempt to log in, I suspect the issue is that you might have forgotten to link to the authenticated page? These are the outputs from terminal:

::1 - - [29/Jun/2018:16:18:57 +0000] "POST /api/user/signin HTTP/1.1" 200 35 "http://localhost:8080/app/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134" ::1 - - [29/Jun/2018:16:18:57 +0000] "GET /app HTTP/1.1" 200 2204 "http://localhost:8080/app/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134"

I also tried the "forgotten password" functionality but I got a Bad Request from SparkPost (I did register for SparkPost and got an API key):

{ SparkPostError: Bad Request at Request._callback (D:\cs490\mern-auth\node_modules\sparkpost\lib\sparkpost.js:102:13) at Request.self.callback (D:\cs490\mern-auth\node_modules\request\request.js:185:22) at Request.emit (events.js:182:13) at Request. (D:\cs490\mern-auth\node_modules\request\request.js:1157:10) at Request.emit (events.js:182:13) at IncomingMessage. (D:\cs490\mern-auth\node_modules\request\request.js:1079:12) at Object.onceWrapper (events.js:273:13) at IncomingMessage.emit (events.js:187:15) at endReadableNT (_stream_readable.js:1081:12) at process._tickCallback (internal/process/next_tick.js:63:19) name: 'SparkPostError', errors: [ { message: 'Message generation rejected', description: 'Sending domain sandbox option mismatch', code: '1902' } ], statusCode: 400 }

Thank you again, I love your code neatness :D

codemzy commented 6 years ago

Hey,

Sorry for the delay in responding to this. I do need to get this repo updated so it is ready to use... I know a few of the dependencies need updating.

For the authentication, you could try looking to check the jwt token cookie has set in your browser. It could be the redirect. Try manually going to /app to see if you are logged in?

When I get some time I will try and get to the bottom of it, but if you manage to narrow it down please do update me 😅

For the sparkpost error, I know the code has changed a bit since I built this...

From this...

exports.welcomeEmail = function (email, emailConfirmCode) {

    sp.transmissions.send({
      transmissionBody: {
        content: {
          from: APP_EMAIL,
          subject: APP_NAME + ': Your new account',
          html:'<html><body><p>Hello and welcome to ' + APP_NAME + '!</p>\
          <p>Thanks so much for joining us.</p>\
          <p>You can login to your ' + APP_NAME + ' account right now to get started.</p>\
          <p>Please click the link below to confirm your email address and fully activate your account.</p>\
          <p>' + emailConfirmCode + '</p>\
          <p>This email confirmation link will expire in 24 hours.</p>\
          <p>Have any questions? Just send us an email! We\'re always here to help.</p>\
          <p>Support at ' + APP_NAME + '</p>\
          </body></html>'
        },
        recipients: [
          {address: email}
        ]
      }
    }, function(err, res) {
      if (err) {
        console.log('Whoops! Something went wrong with the welcomeEmail');
        console.log(err);
      }
    });

};

To this...

  sp.transmissions.send({
        content: {
          from: APP_EMAIL,
          subject: APP_NAME + ': Your new account',
          html:'<html><body><p>Hello and welcome to ' + APP_NAME + '!</p>\
          <p>Thanks so much for joining us.</p>\
          <p>You can login to your ' + APP_NAME + ' account right now to get started.</p>\
          <p>Please click the link below to confirm your email address and fully activate your account.</p>\
          <p>' + emailConfirmCode + '</p>\
          <p>This email confirmation link will expire in 24 hours.</p>\
          <p>Have any questions? Just send us an email! We\'re always here to help.</p>\
          <p>Support at ' + APP_NAME + '</p>\
          </body></html>'
        },
    recipients: [
      {address: email}
    ]
  })
  .then(data => {
    console.log('Success! Just sent the welcomeEmail!');
    console.log(data);
  })
  .catch(err => {
    console.log('Whoops! Something went wrong with the welcomeEmail');
    console.log(err);
  });

(They got rid of the transmissionBody object).

Might need to update to the latest sparkpost package https://www.npmjs.com/package/sparkpost (2.1.2)

Hope that helps!

duongch4 commented 6 years ago

Thank you for reply, i will have a try :D