Skip to main content
8Space uses Supabase Auth for user authentication. The app supports email/password signup, password login, and Google OAuth.

Authentication Methods

Email/Password Signup

Create a new user account with email and password. Endpoint: POST /auth/v1/signup
string
required
User’s email address (must be valid email format)
string
required
User’s password (minimum 6 characters)
string
User’s display name (stored in user metadata)
Example Request:
Response:
The signup method is implemented in use-auth.tsx:155-168 as signUpWithPassword.

Password Login

Sign in with existing credentials. Endpoint: POST /auth/v1/token?grant_type=password
string
required
Must be password for password grant flow
string
required
User’s email address
string
required
User’s password
Example Request:
Response:
The password sign-in method is implemented in use-auth.tsx:149-153 as signInWithPassword.

Google OAuth

Sign in with Google OAuth provider. Endpoint: GET /auth/v1/authorize?provider=google
string
required
OAuth provider, must be google
string
Callback URL after OAuth completes
Example Request:
Response: 302 redirect to Google OAuth consent screen
The Google OAuth method is implemented in use-auth.tsx:170-180 as signInWithGoogle.

Auth Callback

After OAuth completes, Google redirects to the callback route. Endpoint: GET /auth/callback
string
Supabase auth code to exchange for session
string
default:"/app"
Relative redirect path after successful exchange
Response: 302 redirect to next parameter (default /app)
The callback route exchanges the OAuth code for a session and sets cookies before redirecting the user.

Session Management

Get Current User

Retrieve the authenticated user’s information. Endpoint: GET /auth/v1/user Headers:
string
required
Supabase anon/service key
string
required
Bearer token: Bearer {access_token}
Response:

Sign Out

Log out the current user session. Endpoint: POST /auth/v1/logout Headers:
string
required
Supabase anon/service key
string
required
Bearer token: Bearer {access_token}
Example Request:
Response: 200 with empty body
The sign-out method is implemented in use-auth.tsx:182-189 with a fallback to local sign-out if the remote call fails.

Auth Context

8Space provides a React context for managing authentication state throughout the app.

AuthProvider

Wrap your app with AuthProvider to provide auth context:

useAuth Hook

Access authentication state and methods:
Context Values:
Session | null
Current Supabase session object
User | null
Current authenticated user
UserProfile | null
User profile with id, displayName, and avatarUrl
boolean
True during initial session bootstrap (max 15 seconds)
function
(email: string, password: string) => Promise<void>
function
(email: string, password: string, name: string) => Promise<void>
function
() => Promise<void>
function
() => Promise<void>

Session Bootstrap

The AuthProvider automatically restores sessions on mount:
Session bootstrap has a 15-second timeout. If bootstrap takes longer, the local session is cleared and loading completes.
Bootstrap Process:
  1. Call supabase.auth.getSession() to restore session from cookies/localStorage
  2. If session exists, fetch user profile from profiles table
  3. Set session, user, and profile in context
  4. Set loading to false
  5. Subscribe to auth state changes
Timeout Handling:
The bootstrap logic is implemented in use-auth.tsx:74-113.

Auth State Changes

The AuthProvider listens for auth state changes and updates context:
Auth state change listener is implemented in use-auth.tsx:115-132.

Profile Fetching

User profiles are fetched from the profiles table:
The fetchProfile function is implemented in use-auth.tsx:21-41.

Making Authenticated Requests

All Supabase Data and RPC endpoints require authentication: Required Headers:
string
required
Supabase anon key from project settings
string
required
Bearer token with format: Bearer {access_token}
Example:
Row Level Security (RLS) policies enforce access control. A 403 response indicates the user lacks permission for the requested resource.

Error Handling

Common Error Codes:
Bad Request
Invalid credentials or validation error
Unauthorized
Missing or invalid authentication token
Forbidden
User lacks permission (RLS policy denied access)
Error Response Format:

Security Best Practices

Never expose the Supabase service role key in client-side code. Only use the anon key.
  1. Use Row Level Security (RLS): Enable RLS policies on all tables to enforce access control
  2. Validate inputs: Always validate user inputs before sending to the API
  3. Handle token refresh: Supabase automatically refreshes tokens, but handle errors gracefully
  4. Secure redirects: Validate redirect URLs to prevent open redirect vulnerabilities
  5. Use HTTPS: Always use HTTPS in production to protect tokens in transit

Next Steps

API Overview

Explore all available API endpoints