Android Example [B4X] Supabase - Sign In Anonymously


Supabase now supports anonymous user login, the B4X library now too.

Create and use anonymous users to authenticate with Supabase
Enable Anonymous Sign-Ins to build apps which provide users an authenticated experience without requiring users to enter an email address, password, use an OAuth provider or provide any other PII (Personally Identifiable Information). Later, when ready, the user can link an authentication method to their account.

Anonymous sign-ins can be used to build:
  • E-commerce applications, such as shopping carts before check-out
  • Full-feature demos without collecting personal information
  • Temporary or throw-away accounts
Review your existing RLS policies before enabling anonymous sign-ins
Anonymous users use the authenticated role. To distinguish between anonymous users and permanent users, your policies need to check the is_anonymous field of the user's JWT.
See the Access control section for more details.

Abuse prevention and rate limits
Since anonymous users are stored in your database, bad actors can abuse the endpoint to increase your database size drastically. It is strongly recommended to enable invisible Captcha or Cloudflare Turnstile to prevent abuse for anonymous sign-ins. An IP-based rate limit is enforced at 30 requests per hour which can be modified in your dashboard. You can refer to the full list of rate limits here.

More you can read in the official blog post:

B4X:
    Wait For (xSupabase.Auth.LogIn_Anonymously) Complete (AnonymousUser As SupabaseUser)
    If AnonymousUser.Error.Success Then
        Log("Successfully created an anonymous user")
    Else
        Log("Error: " & AnonymousUser.Error.ErrorMessage)
    End If
 
Top