Search code examples
django-rest-frameworkfirebase-authenticationfirebase-console

How can I approve user to register (change the custom claim) in the firebase console?


class RegisterAPIView(APIView):
    def post(self, request, format=None):
        email = request.data.get('email')
        password = request.data.get('password')
        
        # Create user with Firebase
        try:
            user = auth.create_user(email=email, password=password)
        except auth.EmailAlreadyExistsError:
            return JsonResponse({'error': 'Unable to create account'})

        # Set custom user claims for the new user
        auth.set_custom_user_claims(user.uid, {'is_approved': False})
        
        return JsonResponse({'success': 'Account created successfully'})

This is a Django REST Framework API, which is creating a new user in fireabase and setting custom claim is_approved False. After registration the user appears in the firebase console. How can I approve user to register (change the custom claim) in the firebase console? I can do it with code but can't manage in the console.


Solution

  • There is no way to change a user's custom claims in the Firebase console. To change a user's custom claim, you'll have to call the API as you already do.

    The only alternative I know off is the Set Auth claims with Firestore experimental extension, which synchronizes claims for a user between their auth profile and a companion document in Firestore.