Hi, I wanna add email/password auth along with email verification. here is my code, I don't know why...
h
Hi, I wanna add email/password auth along with email verification. here is my code, I don't know why it does not send verification email
Copy code
recipeList: [
        EmailPassword.init(),
        EmailVerification.init({
            mode: "REQUIRED",
            emailDelivery: {
                override: (originalImplementation) => {
                    return {
                        ...originalImplementation,
                        sendEmail: async function (input) {
                            console.log('send email verification');
                            sendEmail();
                        }
                    }
                }
            },
            override: {
                apis: (originalImplementation) => {
                    return {
                        ...originalImplementation,
                        generateEmailVerifyTokenPOST: async function (input) {
                            console.log('generate email verification token');
                        },
                        isEmailVerifiedGET: async function (input) {
                            console.log('is email verified');
                        },
                        verifyEmailPOST: async function (input) {
                            console.log('send email verification');

                            if (originalImplementation.verifyEmailPOST === undefined) {
                                throw Error("Should never come here");
                            }
                            let response = await originalImplementation.verifyEmailPOST(input);
                            if (response.status === "OK") {
                                let { id, email } = response.user;
                            }
                            return response;
                        }
                    }
                }
            }
        }),
        Session.init()
    ]
});
r
In your override for sendEmail, you should do
originalImplementation.sendEmail()
and not just call
sendEmail
by itself. The API calls should be prefixed with the apiBasePath whose default value is
/auth
. So you should send a request to
/auth/user/email/verify
(or whatever you have set your apiBasePath to be.
can you also edit your message in this thread to include the original question and not just the code snippet?
h
at which step should I expect email verificationto be sent? by calling GET /auth/user/verify/email or after signin?
r
no. The POST API -
generateEmailVerifyTokenPOST
one.
h
POST /auth/user/email/verify/token ?
r
POST /auth/user/email/verify/token
h
I get unauthorized error. how should I pass the access token within header?
r
if you are using postman, see our docs for testing with postman
h
here is an example of the verifyLink
http://localhost:3000/auth/verify-email?token=YWMwYjg1NTEzYzZkYTM3MWJlNWE3ZjdmYWI1ZDRlOWE5NTkxYjIwYjQ0OTc3OGFjNmIzNGIwMGQ2MTU3ZDc0OTY5YjJmMDhmOWE5ZDJhMGQ0OTNiM2RhNTQwODJlMDVl&rid=emailverification
that when I hit it I get
Cannot GET /auth/verify-email
r
this link should point to your frontend app. Is localhost:3000 your frontend app?
h
no I just have a backend and I want to implement the backend side only and test it by postman
r
right. So this link should point to your frontend, and that frontend app should send a request to the
/{apiBasePath}/user/email/verify
endpoint with the token in the link
h
how should I pass the token by /user/email/verify?
r
see our API spec please.
h
great, worked, thanks
2 Views