0

To start off, I do want to clarify that I know how to use APi's created in NodeJS in Angular. The problem I have is a little tricky.

I have a function that verifies the email used in registering:

exports.confirmEmail = function (req, res) {
    ConfirmToken.findOne({
        token: req.params.token
    }, function (err, token) {

        if (err) {
            return res.status(500).send({
                message: "Internal Server Error " + err
            })
        }

        // token is not found into database i.e. token may have expired 
        if (!token) {
            return res.status(400).send({
                message: 'Your verification link may have expired. Please click on resend for verify your Email.'
            });
        }
        // if token is found then check valid user 
        else {
            Account.findOne({
                _id: token._accountId,
                email: req.params.email
            }, function (err, user) {

                if (err) {
                    return res.status(500).send({
                        message: "Internal Server Error " + err
                    })
                }
                // User does not exist
                if (!user) {
                    return res.status(401).send({
                        message: 'The account does not exist'
                    });
                }
                // user is already verified
                else if (user.isVerified) {
                    return res.status(200).send('User has been already verified. Please Login');
                }
                // verify user
                else {
                    // change isVerified to true
                    user.isVerified = true;
                    user.save(function (err) {
                        // error occur
                        if (err) {
                            return res.status(500).send({
                                message: err.message
                            });
                        }
                        // account successfully verified
                        else {
                            return res.status(200).send('Your account has been successfully verified');
                        }
                    });
                }
            });
        }

    })
}

This is the response I get when I register an account After Registration

Now my question is: is there a way to pass in html code or have it show in a custom Angular component instead of displaying as simple plain text on the web browser as such

Response after clicking verify email

5
  • Node and angular are two different technologies. There is nothing called NodeJS in Angular Commented Apr 29, 2021 at 5:39
  • You can send the Html code in response instead of a string. And then in Angular component use innerHtml to render Html. Commented Apr 29, 2021 at 5:42
  • Why don't you just write an angular component to show whenever you get that response? Or just attach some styles to it? Careful with passing html that way, you could be vulnerable to XSS attacks. Commented Apr 29, 2021 at 6:02
  • @Charlie Yes, I know. I stated in my questions that I created API's in nodejs to be used in angular. Commented Apr 29, 2021 at 15:01
  • @ale917k Thank you for the suggestion! For some reason, I forgot you could send more than just a string in a response. I am not sure why since I did it in other methods Commented Apr 29, 2021 at 15:03

1 Answer 1

1

Your service should send a isVerified status back to the client. You are sending only a string at the moment

return res.status(200).send('Your account has been successfully verified');

based on this status, let's call it, isVerified your angular app would render a isVerfiedComponent.ts or notVerifiedComponent.ts

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my gosh! Of course, I did it for my other methods in my backend but not for this one so I got lost: so res.status(200).send({ message: "The account has been verified", isVerified: true}): I guess I was having a hard time wrapping my head around the logic because of click on verify from gmail instead of angular component

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.