ScaleRocket/Mobile

Authentication

Set up email/password, Google OAuth, and Apple Sign-In for your mobile app.

Authentication

ScaleRocket Mobile includes a complete authentication flow with email/password, Google OAuth, and Apple Sign-In.

Auth Screens

The boilerplate includes three auth screens in app/(auth)/:

ScreenFileDescription
Loginlogin.tsxEmail/password + Google/Apple OAuth buttons
Registerregister.tsxAccount creation with optional full name
Forgot Passwordforgot-password.tsxPassword reset via email

Email/Password

Email and password authentication works out of the box. The login and register screens include validation and error handling.

// lib/auth.ts
import { supabase } from "./supabase";

export async function signIn(email: string, password: string) {
  const { error } = await supabase.auth.signInWithPassword({ email, password });
  if (error) throw error;
}

export async function signUp(email: string, password: string, fullName?: string) {
  const { error } = await supabase.auth.signUp({
    email,
    password,
    options: { data: { full_name: fullName } },
  });
  if (error) throw error;
}
// lib/auth.ts
import { useConvexAuth } from "convex/react";

export function useSession() {
  const { isAuthenticated, isLoading } = useConvexAuth();
  return { isAuthenticated, loading: isLoading };
}

// Sign in and sign up are handled by the Convex auth provider
// configured in convex/auth.ts

Google OAuth

Google OAuth opens the device browser for sign-in and redirects back to the app via the scalerocket:// deep link scheme.

Setup

  1. Go to Supabase Dashboard > Authentication > Providers > Google
  2. Enable the Google provider
  3. Create OAuth credentials in Google Cloud Console
  4. Add the Client ID and Secret to Supabase
  5. Add scalerocket:// to your Supabase Redirect URLs

Code

import { makeRedirectUri } from "expo-linking";

export async function signInWithOAuth(provider: "google" | "apple") {
  const redirectUrl = makeRedirectUri({ scheme: "scalerocket" });
  const { error } = await supabase.auth.signInWithOAuth({
    provider,
    options: { redirectTo: redirectUrl },
  });
  if (error) throw error;
}

Setup

  1. Configure Google OAuth in your Convex dashboard
  2. Add the OAuth credentials to your Convex auth configuration in convex/auth.ts
  3. Set the redirect URL to scalerocket://

Code

// Google OAuth is configured in convex/auth.ts
// The login screen calls the Convex auth provider directly

Apple Sign-In

Apple Sign-In is required for iOS apps that offer third-party sign-in. It is conditionally rendered only on iOS devices.

import { Platform } from "react-native";

{Platform.OS === "ios" && (
  <TouchableOpacity onPress={() => signInWithOAuth("apple")}>
    <Text>Sign in with Apple</Text>
  </TouchableOpacity>
)}

Setup

  1. Enable Apple provider in your backend dashboard
  2. Configure a Service ID in your Apple Developer account
  3. Add the Service ID to your backend provider settings

Important: Apple requires that any app offering third-party sign-in (like Google) must also offer Apple Sign-In. Your app may be rejected from the App Store without it.

Session Management

Sessions are managed automatically:

  • Storage — Tokens are stored in expo-secure-store (encrypted on device)
  • Auto-refresh — Tokens are refreshed before expiry
  • Persistence — Sessions survive app restarts
  • State listeneronAuthStateChange updates the UI in real time
  • Sign out — Clears the session and redirects to login

Auth Guard

The root layout (app/_layout.tsx) contains the auth guard:

  1. On launch, useSession() checks for an existing session
  2. While checking, a loading spinner is displayed
  3. No session found — redirects to /(auth)/login
  4. Session found — redirects to /(tabs) (home dashboard)
  5. Session changes are handled automatically via the state listener

On this page