Is it possible to limit the number of devices a user can log in to a Firebase app with?

Viewed 595

Context: I'm helping update a Cordova app using Vue to move from a subscription-based revenue, where the user has to pay in order to access the app, to an ad-based revenue, where the user can sign up for free but will have ads displayed in the app as they're using it. Part of what we want to do is limit the number of devices that a user can have an account on to avoid someone deciding to share their paid account with a thousand of their friends. I'm looking to emulate what Netflix does with their accounts.

Netflix too many accounts screen

This is the workflow I had in mind using the email/password authentication (https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signinwithemailandpassword)

// I would like to have device information at this point in the application
firebase.auth().signInWithEmailAndPassword(email, password)
    .then(function(result) {
        // Use Realtime Database to associate the device with the user
    })
    .catch(function(error) {
        // I'd like to catch the "too-many-devices" error here, but if needed, I can use the success handler to check device limits
    })

Unfortunately, the error codes listed in the documentation don't mention a "too-many-devices" sort of error, which means that Firebase Authentication most likely doesn't have the functionality I'm looking for built into it.

According to this support documentation (https://support.google.com/firebase/answer/6318039?hl=en), it sounds like Firebase Analytics has some way to identify the device already. I would like to access that if possible. Other searches I've done always seem to point me to auth limits (https://firebase.google.com/docs/auth/limits), which doesn't mention anything about unique devices.

Is it possible to limit the number of devices a user can log in to a Firebase app with?

1 Answers

Firebase Auth does not provide any mechanism to track or limit how many devices the user is using. In fact all it really does is expose public APIs that can be used from anywhere on the internet. It does not hold a sense of "device" at all.

If you want to limit the number of devices that a user can use, that's something you'll have to somehow implement that yourself. Since Firebase allows essentially unlimited sign-ins from any source, you won't be able to enforce this strictly. Someone will be able to find a way to work around whatever you implement. But you can certainly perform a lot of checks in your app to make sure that distinct devices are being tracked and limited, and assume that end users will not try to work around your limitations.

Related