Hei, I'm getting the following error whenever I run `EmailVerification.sendVerificationEmail()`. `Un...
l
Hei, I'm getting the following error whenever I run
EmailVerification.sendVerificationEmail()
.
Uncaught (in promise) SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Anything I'm missing or is this a bug? I'm using the
web.js
sdk, and I'm initializing the recipe. Also tested with
EmailPassword.sendVerificationEmail()
and that works fine. > Note: I'm I correct in saying that you have to have a valid session before sending the email?
I had forgot to add the
EmailVerification.init()
on the backend. After fixing that, the error got resolved. Maybe a check for this with a better error msg could be added?
r
Hey! You don’t actually have to do emailverification.init on the backend. There should be a emailVerification: {…} config that you can add to the auth recipe you ate initialising (for example EmailPassword has that config.
And on the frontend, you can use EmailPassword.sendVerificationEmail(). So you should use that
Also, yes, you are right. Calling this function requires a valid session, but consuming the verification link doesn’t.
a
Hi rp, me again 😅 Any python / fastapi examples for this? Do we need to instantiate a
InputEmailVerificationConfig
object to pass to that
email_verification_feature
config param?
r
are you using emailpassword recipe?
You need to enable email verification from the frontend -> see this: https://supertokens.com/docs/emailpassword/common-customizations/email-verification/about
a
Alas, I'm using the custom Vue stuff from yesterday. It looks like it works by adding
email_verification_feature=emailpassword.InputEmailVerificationConfig()
to the backend
init()
and
EmailVerification.init()
to the frontend
init()
, now I can use
EmailPassword.isEmailVerified()
and the rest. But am I missing anything by initiating that empty
InputEmailVerificationConfig()
object?
r
Hmm. You shouldn't need to do email verification init on the frontend. Just doing EmailPassword.init() should be fine on the frontend.
Also on the backend, you should not need to do
email_verification_feature
either.
What error are you getting?
a
No errors now, just didn't know exactly what needed to be enabled and where, for a custom
web-js
install. So no need for backend init, this means the email verify routes are created with EmailPassword by default, right? No frontend init required, either?
r
> So no need for backend init, this means the email verify routes are created with EmailPassword by default, right? Exactly. > No frontend init required, either? Correct. The EmailPassword.init on the frontend also uses email verification internally. You can directly use EmailPassword.isEmailVerified function for example.
a
Yup, you're right. Just removed everything and the previous frontend
EmailPassword.<email stuff>
calls work. Thank you!
r
nice
a
So we need to write custom backend code to limit API endpoints to only-verified users 😅
Don't you hate it when devs want everything for free?? 🤣
r
Yea.. at the moment you do. We are working on doing all this automatically... but right now, you do.
a
Soo... followup. From within a FastAPI Depends-provided session, how would I access the email verification boolean? Is there anything in the Python SDK for that, or do I need to hit the Core API?
I'm looking through the docs, thought I remembered a method to get user data, including email
r
The easiest way implementation wise would be to: Do session verification first. Then call a function from the python SDK to check if the email is verified - this would hit the core each time. If the result is false, deny access and redirect user to email verification flow on the frontend. If the result is true, update the access token payload to say that the email is verified so the in future API calls, you can check the payload first to know if it's verified or not.
> I'm looking through the docs, thought I remembered a method to get user data, including email syncio: https://supertokens.com/docs/python/recipe/emailpassword/syncio/index.html asyncio: https://supertokens.com/docs/python/recipe/emailpassword/asyncio/index.html There is a
is_email_verified
function
a
That's where it was! On the recipe itself, not the request's session 🤦‍♂️ Thank you!