I am trying to implement email otp using supabase via a flask backend (and working with a swift frontend). So far I have been able to implement a "send-otp" route that generate an otp and send it to my email, but I'm struggling with writing the follow up "verify_otp" function.

In the supabase docs for Python, below is all they say about the function. However, I need to figure out how to implement it specifically for email with otp. I know it should have something to do with the "signup" option, but I don't know anything beyond that on how I can set up the function and I need more clarification. I've looked everywhere (stackoverflow, reddit, supabase docs) on more on the verify_otp function, but this is all I could find.

*Verify and log in through OTP

The verify_otp method takes in different verification types. If a phone number is used, the type can either be sms or phone_change. If an email address is used, the type can be one of the following: signup, magiclink, recovery, invite or email_change. The verification type used should be determined based on the corresponding auth method called before verify_otp to sign up / sign-in a user.*

res = supabase.auth.verify_otp(phone, token)

my best guess on how it should be structured:

@stylist_bp.route('/verify-otp', methods=['POST'])
def verify_otp():
    data = request.get_json()
    email = data.get('email')
    otp = data.get('otp')

    try:
        # Verify the OTP
        verify_response = supabase.auth.verify_otp({
            'email': email,
            'token': otp,
            'type': 'email'
        })

        session = verify_response.data.session
        return jsonify({'session': session}), 200
    except AttributeError as e:
        return jsonify({'error': str(e)}), 500

What I've tried so far: As described earlier, I have been reading the supabase documentation and I have tried going through forums, but I cannot find further instructions on how to properly format the verify_otp function for my needs.

0

There are 0 best solutions below