Skip to main content
8Space uses Supabase Auth for secure authentication with support for email/password and OAuth providers.

Overview

Authentication features:
  • Email/password authentication
  • Google OAuth integration
  • Automatic profile creation
  • Session persistence
  • Auto-refresh tokens
  • Row Level Security (RLS) integration

Supabase Client Configuration

The authentication client is configured in packages/app/src/integrations/supabase/client.ts:
The client includes fallback values for local development, so you can start coding without configuration.

Email Authentication

Email/password authentication is enabled by default in Supabase.

Configuration

1

Local Development

No additional configuration needed. Supabase local instance has email auth enabled.
2

Production

Configure email settings in Supabase Dashboard:
  1. Navigate to Authentication → Settings
  2. Configure Email Templates (optional)
  3. Set up SMTP settings (optional, uses Supabase’s SMTP by default)

Email Verification

By default, Supabase requires email verification. You can disable this in:
  • Local: packages/app/supabase/config.toml
  • Production: Supabase Dashboard → Authentication → Settings → Email Auth
packages/app/supabase/config.toml

Google OAuth

Google OAuth allows users to sign in with their Google account.

Setup Instructions

1

Create Google OAuth Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Enable Google+ API
  4. Navigate to Credentials → Create Credentials → OAuth 2.0 Client ID
  5. Set Application Type to “Web application”
2

Configure Redirect URIs

Add authorized redirect URIs:Local development:
Production:
3

Add Credentials to Environment

Add to packages/landing/.env.local:
4

Configure Supabase

Local development (packages/app/supabase/config.toml):
Production (Supabase Dashboard):
  1. Navigate to Authentication → Providers
  2. Enable Google
  3. Add Client ID and Client Secret
Never commit GOOGLE_CLIENT_SECRET to version control. Use environment variables or secret management.

Profile Creation

Automatic Profile Handling

When a user signs up, a trigger automatically creates their profile:
This trigger:
  • Extracts name from OAuth metadata (supports Google)
  • Falls back to email prefix if no name provided
  • Handles both avatar_url and picture fields
  • Updates existing profiles on conflict

Profile Fields

The profiles table stores user information:

Session Management

Session Persistence

Sessions are automatically persisted to localStorage:

Getting Current User

Auth State Changes

Row Level Security

Auth Integration

RLS policies use auth.uid() to enforce permissions:

Tenant Access

Tenant access is controlled via membership:
The is_tenant_member() function checks the current user’s tenant membership:

Testing Authentication

Local Test Accounts

The seed file creates test users (password: password123):

Sign In Flow

Security Best Practices

Environment Variables

Store OAuth secrets in environment variables, never in code

HTTPS Only

Always use HTTPS in production for OAuth callbacks

Row Level Security

Enable RLS on all tables to enforce access control

Token Refresh

Enable auto-refresh to prevent session expiration

Troubleshooting

Ensure redirect URI matches exactly:
Note: Use 127.0.0.1, not localhost (Google treats them differently).
Check that persistSession: true is set in client configuration. Clear localStorage and try again:
Check that the trigger exists:
Re-run migrations if missing:

Additional Providers

Supabase supports many OAuth providers. To add more:
  1. Enable provider in Supabase Dashboard or config.toml
  2. Add credentials to environment variables
  3. Update the handle_new_user() function if provider uses different metadata fields
Supported providers:
  • GitHub
  • GitLab
  • Bitbucket
  • Azure
  • Facebook
  • Twitter
  • Discord
  • And more…

Next Steps

Database Setup

Understand the profile and user schema

Environment Variables

Configure all required variables