Add Supabase Auth logo

Add Supabase Auth

Community
khadinakbarlabs
add-supabase-auth

Add Supabase Auth to a React Native + Expo app with Apple Sign In, email magic link, and session management. Use when the user says 'add supabase auth', 'apple sign in supabase', 'magic link rn', 'auth setup', 'supabase login'.

Overview

Publisherkhadinakbarlabs
Repositoryexpo-mobile-app-builder
Skill nameadd-supabase-auth
Stars
3
Forks
0
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by khadinakbarlabs on GitHub. Read the source before you install it.

Installation

Install the Add Supabase Auth AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/khadinakbarlabs/expo-mobile-app-builder/tree/main/skills/add-supabase-auth
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/khadinakbarlabs/expo-mobile-app-builder.git /tmp/expo-mobile-app-builder
mkdir -p .claude/skills
cp -r /tmp/expo-mobile-app-builder/skills/add-supabase-auth .claude/skills/add-supabase-auth
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Add Supabase Auth in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Add Supabase Auth on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Add Supabase Auth is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Add Supabase Auth to RN + Expo

Use app-owned public project configuration, persistent sessions and validated magic-link callbacks. These examples belong to the consuming app; the installed plugin has no authentication service or credential reader. Preserve an existing app's auth provider and navigation unless migration is explicitly requested.

Install

In the consuming Expo app, after dependency changes are authorized:

bash
pnpm add @supabase/supabase-js react-native-url-polyfill
npm exec --no -- expo install @react-native-async-storage/async-storage expo-apple-authentication expo-linking

Explicit public client configuration

Obtain the intended app's Project URL and publishable key from its owner. Create lib/public-config.ts exporting publicSupabaseConfig with url and publishableKey. These are public app configuration, not plugin configuration. Do not discover values from the installer's environment, local credentials or unrelated projects. Never place a secret or service-role key in the mobile bundle; use Row Level Security for every exposed table. Existing legacy anon-key projects should follow Supabase's migration guidance before using this publishable-key example.

lib/supabase.ts:

ts
import 'react-native-url-polyfill/auto';
import { Platform } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createClient } from '@supabase/supabase-js';
import { publicSupabaseConfig } from './public-config';

function createAppSupabase(config: { url: string; publishableKey: string }) {
  const url = new URL(config.url);
  if (url.protocol !== 'https:' || url.username || url.password ||
      url.search || url.hash || url.pathname !== '/' ||
      !config.publishableKey.startsWith('sb_publishable_')) {
    throw new Error('Provide the intended app public Supabase configuration.');
  }
  return createClient(url.origin, config.publishableKey, {
    auth: {
      ...(Platform.OS !== 'web' ? { storage: AsyncStorage } : {}),
      autoRefreshToken: true,
      persistSession: true,
      detectSessionInUrl: false,
      flowType: 'pkce',
    },
  });
}

export const supabase = createAppSupabase(publicSupabaseConfig);

Native session storage contains this app's signed-in user session. AsyncStorage is unencrypted; choose a platform-supported protected storage adapter when the app's threat model requires it. No app session, key or callback URL belongs in logs or analytics.

Magic link and callback

Register the app's chosen scheme and exact redirect in the Supabase Auth redirect allowlist. The example below uses yourapp://auth/callback; replace it consistently. Rebuild the development binary after scheme changes and test on both iOS and Android.

json
{
  "expo": {
    "scheme": "yourapp",
    "ios": { "usesAppleSignIn": true },
    "plugins": ["expo-apple-authentication"]
  }
}
ts
export const AUTH_REDIRECT = 'yourapp://auth/callback';

export async function sendMagicLink(email: string) {
  const { error } = await supabase.auth.signInWithOtp({
    email,
    options: { emailRedirectTo: AUTH_REDIRECT },
  });
  if (error) throw new Error('Could not send the sign-in link. Please try again.');
}

The PKCE client persists its verifier before sending the link. Open the link on the same device/app that initiated sign-in. Expired, reused or cross-device links need a fresh request; disable overlapping sign-in requests. Do not mix implicit token-fragment callbacks with this PKCE example.

Copy this handler into the app. It checks the exact destination before passing a one-time code to the configured Supabase client, rejects ambiguous/error payloads, deduplicates warm/cold deliveries and exposes generic errors.

js
// lib/auth-callback.js
export function createAuthCallbackHandler(client, redirectTo) {
  const expected = new URL(redirectTo);
  let lastCode = null;
  let lastResult = null;
  const failed = () => new Error('Sign-in could not be completed. Request a new link.');
  return async function handleAuthCallback(rawUrl) {
    let url;
    try { url = new URL(rawUrl); } catch { return 'ignored'; }
    if (url.protocol !== expected.protocol || url.hostname !== expected.hostname ||
        url.port !== expected.port || url.pathname !== expected.pathname ||
        url.username || url.password) return 'ignored';
    const codes = url.searchParams.getAll('code');
    if (url.hash || url.searchParams.has('error') || url.searchParams.has('error_code') ||
        codes.length !== 1 || !codes[0].trim() || codes[0].length > 4096) throw failed();
    const code = codes[0];
    if (code === lastCode && lastResult) return lastResult;
    lastCode = code;
    lastResult = Promise.resolve().then(async () => {
      const { data, error } = await client.auth.exchangeCodeForSession(code);
      if (error || !data?.session) throw failed();
      return 'signed-in';
    }).catch(() => {
      if (lastCode === code) { lastCode = null; lastResult = null; }
      throw failed();
    });
    return lastResult;
  };
}

Register once in the root layout. Keep an app/auth/callback.tsx route accessible while signed out so Expo Router can resolve the link before the protected app group opens. Its screen should show a waiting state and generic retry action, never render URL parameters.

tsx
import { useEffect } from 'react';
import { Alert } from 'react-native';
import * as Linking from 'expo-linking';
import { supabase } from '@/lib/supabase';
import { AUTH_REDIRECT } from '@/lib/auth-redirect';
import { createAuthCallbackHandler } from '@/lib/auth-callback';

// Export AUTH_REDIRECT from lib/auth-redirect.ts and import it in sendMagicLink too.
const handleAuthCallback = createAuthCallbackHandler(supabase, AUTH_REDIRECT);

export function useAuthLinks() {
  useEffect(() => {
    let mounted = true;
    const receive = async (url: string) => {
      if (!mounted) return;
      try { await handleAuthCallback(url); }
      catch { if (mounted) Alert.alert('Sign-in failed', 'Request a new link and open it in this app.'); }
    };
    const sub = Linking.addEventListener('url', ({ url }) => { void receive(url); });
    void Linking.getInitialURL().then(url => { if (url) void receive(url); })
      .catch(() => { if (mounted) Alert.alert('Sign-in failed', 'Please reopen the sign-in link.'); });
    return () => { mounted = false; sub.remove(); };
  }, []);
}

Session and protected routes (SDK 54)

Call the session hook once at the layout/provider boundary. Subscribe before loading stored state so a completed callback cannot be overwritten by an older session read.

tsx
import { useEffect, useState } from 'react';
import { AppState, Platform } from 'react-native';
import type { Session } from '@supabase/supabase-js';
import { supabase } from '@/lib/supabase';

export function useSession() {
  const [session, setSession] = useState<Session | null>(null);
  const [loading, setLoading] = useState(true);
  const [failed, setFailed] = useState(false);
  useEffect(() => {
    let mounted = true;
    let observedAuth = false;
    const { data: { subscription } } = supabase.auth.onAuthStateChange((_, next) => {
      observedAuth = true;
      if (mounted) { setSession(next); setLoading(false); setFailed(false); }
    });
    void supabase.auth.getSession().then(({ data, error }) => {
      if (!mounted || observedAuth) return;
      setSession(error ? null : data.session); setFailed(Boolean(error)); setLoading(false);
    }).catch(() => { if (mounted && !observedAuth) { setFailed(true); setLoading(false); } });
    const refresh = (state: string) => {
      if (state === 'active') supabase.auth.startAutoRefresh();
      else supabase.auth.stopAutoRefresh();
    };
    const listener = Platform.OS !== 'web' ? AppState.addEventListener('change', refresh) : null;
    if (Platform.OS !== 'web') refresh(AppState.currentState);
    return () => {
      mounted = false; subscription.unsubscribe(); listener?.remove();
      if (Platform.OS !== 'web') supabase.auth.stopAutoRefresh();
    };
  }, []);
  return { session, loading, failed };
}

In the root layout use Expo Router's Stack.Protected, not conditional Stack.Screen declarations. Put the callback inside the signed-out guard: successful authentication removes its waiting screen and opens the app group, including when an already signed-in user opens a callback link. Keep (auth) first so signed-out fallback opens login instead of the waiting callback. This protects navigation only; enforce server authorization and database RLS independently.

tsx
import { Stack } from 'expo-router';
import { ActivityIndicator, Text } from 'react-native';
import { useSession } from '@/hooks/useSession';
import { useAuthLinks } from '@/hooks/useAuthLinks';

export default function RootLayout() {
  useAuthLinks();
  const { session, loading, failed } = useSession();
  if (loading) return <ActivityIndicator accessibilityLabel="Loading account" />;
  if (failed) return <Text>Account could not load. Reopen the app to retry.</Text>;
  return <Stack>
    <Stack.Protected guard={!session}>
      <Stack.Screen name="(auth)" />
      <Stack.Screen name="auth/callback" />
    </Stack.Protected>
    <Stack.Protected guard={Boolean(session)}><Stack.Screen name="(app)" /></Stack.Protected>
  </Stack>;
}

Apple sign-in and platform parity

Native expo-apple-authentication is iOS-only. Check AppleAuthentication.isAvailableAsync() before rendering its button; give it explicit width and height. On press, call signInAsync, require a non-empty identityToken, and pass it to supabase.auth.signInWithIdToken({ provider: 'apple', token: credential.identityToken }). Treat ERR_REQUEST_CANCELED as cancellation; show a generic retry message for other errors. Never log provider credentials. Configure the iOS bundle ID and capability with the app owner. Android retains the same magic-link/session flow; an Apple browser OAuth option needs a separately configured Services ID and browser callback flow.

Use the current Apple 4.8 guideline to determine whether an equivalent login option is required; exceptions exist. Do not assume every social-login app has identical obligations. Store Apple's name/email only when provided and consented; relay email is valid. Verify Apple sign-in on a real supported device.

Verification and references

Pair with choose-backend, account-deletion-flow, and 5-1-2-i-ai-disclosure where applicable.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Add Supabase Auth AI skill do?

Add Supabase Auth to a React Native + Expo app with Apple Sign In, email magic link, and session management. Use when the user says 'add supabase auth', 'apple sign in supabase', 'magic link rn', 'auth setup', 'supabase login'.

Why use Add Supabase Auth on TypingMind?

Because you install it once and use it with any model. Add Supabase Auth is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Add Supabase Auth in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/khadinakbarlabs/expo-mobile-app-builder/tree/main/skills/add-supabase-auth. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Add Supabase Auth?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Add Supabase Auth?

As many as you like. As long as a model supports skills, you can use Add Supabase Auth with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Add Supabase Auth AI skill free?

Yes. It is published on GitHub by khadinakbarlabs under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇