2

The currentUser.unverifiedEmail variable, which is public, is always empty on front end even after email change.

I thought it was a bug. I contacted Craft support about this, and here is Brad's answer:

That's expected behavior... the default UserQuery (which is what {{ currentUser }} is) only grabs a small subset of columns in it's select to avoid exposing potentially sensitive user account information throughout the system. https://github.com/craftcms/cms/blob/develop/src/elements/db/UserQuery.php#L310-L325

If you want anything outside of that, you'll have to query for the data directly.

I tried this custom query: {{ craft.users.id(currentUser.id).one().unverifiedEmail }}. But even after requesting an email change, the value remain empty.

Any idea how to make this query from Twig?

1 Answer 1

2

You need to select the value

{% set user = craft.users
    .id(currentUser.id)
    .addSelect(['users.unverifiedEmail'])
    .one()
%}
{{ user.unverifiedEmail }}
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.