Skip to content

feat: Add and use email verification claim #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 5, 2022

Conversation

KShivendu
Copy link
Contributor

Summary of change

Add and use email verification claim

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here highlighting the necessary changes)

Checklist for important updates

  • Changelog has been updated
  • coreDriverInterfaceSupported.json file has been updated (if needed)
    • Along with the associated array in supertokens_python/constants.py
  • frontendDriverInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In setup.py
    • In supertokens_python/constants.py
  • Had installed and ran the pre-commit hook
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • If have added a new web framework, update the supertokens_python/utils.py file to include that in the FRAMEWORKS variable
  • If added a new recipe that has a User type with extra info, then be sure to change the User type in supertokens_python/types.py

@KShivendu KShivendu self-assigned this Aug 8, 2022
Comment on lines 210 to 227
#
# class InputEmailVerificationConfig:
# def __init__(
# self,
# get_email_verification_url: Union[
# Callable[[User, Dict[str, Any]], Awaitable[str]], None
# ] = None,
# create_and_send_custom_email: Union[
# Callable[[User, str, Dict[str, Any]], Awaitable[None]], None
# ] = None,
# ):
# self.get_email_verification_url = get_email_verification_url
# self.create_and_send_custom_email = create_and_send_custom_email
#
# if create_and_send_custom_email:
# deprecated_warn(
# "create_and_send_custom_email is deprecated. Please use email delivery config instead"
# )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this. Why commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -371,7 +313,7 @@ def __init__(
sign_up_feature: SignUpFeature,
sign_in_feature: SignInFeature,
reset_password_using_token_feature: ResetPasswordUsingTokenFeature,
email_verification_feature: ParentRecipeEmailVerificationConfig,
# email_verification_feature: ParentRecipeEmailVerificationConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this - why commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -380,19 +322,18 @@ def __init__(
self.sign_up_feature = sign_up_feature
self.sign_in_feature = sign_in_feature
self.reset_password_using_token_feature = reset_password_using_token_feature
self.email_verification_feature = email_verification_feature
# self.email_verification_feature = email_verification_feature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this - why commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 349 to 352
# if email_verification_feature is not None and not isinstance(email_verification_feature, InputEmailVerificationConfig): # type: ignore
# raise ValueError(
# "email_verification_feature must be of type InputEmailVerificationConfig or None"
# )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove all things that are commented like this.. not sure why you did this

Copy link
Contributor Author

@KShivendu KShivendu Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this. Looked for more using Ctrl+F. Didn't find any others.

user, user_context
)
api_options.app_info.website_domain.get_as_string_dangerous()
+ api_options.app_info.website_base_path.get_as_string_dangerous()
+ "?token="
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ "?token="
+ "/reset-password?token="

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

EmailVerificationClaim = EmailVerificationClaimClass()


class APIImplementation(APIInterface):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this moved into this file and not kept in the other file?

Copy link
Contributor Author

@KShivendu KShivendu Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a cyclic import error that kept me stuck for hours. I still don't know how to fix it. Generally, this happens because of types so we just use from _future__ import annotations and from typing import TYPE_CHECKING.

But here we are using using the class (not just its type) so the error is really hard to get rid of. I have already struggled with it for hours. The only feasible solution for now was to move the conflicting classes in the same file.

Need some help to fix it.

self.get_email_for_user_id_funcs_from_other_recipes.append(f)


class EmailVerificationClaimClass(BooleanClaim):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this class in this file and not in the ev_claim.py file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move the content to avoid cyclic import errors. It's really troublesome this time. Have already wasted hours. Need help to fix it.


return UnknownUserIdError()

def add_get_email_for_user_id_func(self, f: Callable[[str, Dict[str, Any]], Any]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the f argument so badly typed? Why is the return of it Any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

self.validators = EmailVerificationClaimValidators(claim=self)


EmailVerificationClaim = EmailVerificationClaimClass()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will the end user import this in their code (if they want to)?

Copy link
Contributor Author

@KShivendu KShivendu Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from supertokens_python.recipe.emailverification import EmailVerificationClaim

I know EmailVerificationClaim and EmailVerificationClaimClass() shouldn't be in recipe.py. But a nasty cyclic import error comes up if I seperate them. Need help in fixing it.

is_verified = await session.get_claim_value(
EmailVerificationClaim, user_context
)
# TODO: Type of is_verified should be bool. It's any for now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

@rishabhpoddar rishabhpoddar merged commit a038414 into feat/session-grants Sep 5, 2022
@rishabhpoddar rishabhpoddar deleted the feat/ev-claim branch September 5, 2022 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants