> ## Documentation Index
> Fetch the complete documentation index at: https://docs.8space.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Supabase Auth endpoints for user authentication and session management in 8Space

8Space uses Supabase Auth for user authentication, supporting email/password and OAuth (Google) sign-in.

## Client Setup

The Supabase client is initialized with auto-refresh and session persistence:

```typescript packages/app/src/integrations/supabase/client.ts theme={null}
import { createClient } from '@supabase/supabase-js';

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
  auth: {
    autoRefreshToken: true,
    persistSession: true,
    detectSessionInUrl: true,
  },
});
```

## Sign Up

Create a new user account with email and password.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const { data, error } = await supabase.auth.signUp({
    email: 'user@example.com',
    password: 'securePassword123',
    options: {
      data: {
        name: 'John Doe'
      }
    }
  });
  ```

  ```bash cURL theme={null}
  curl -X POST 'https://your-project.supabase.co/auth/v1/signup' \
    -H 'Content-Type: application/json' \
    -H 'apikey: YOUR_ANON_KEY' \
    -d '{
      "email": "user@example.com",
      "password": "securePassword123",
      "options": {
        "data": {
          "name": "John Doe"
        }
      }
    }'
  ```
</CodeGroup>

### Request Body

<ParamField body="email" type="string" required>
  User email address
</ParamField>

<ParamField body="password" type="string" required>
  User password (minimum 6 characters)
</ParamField>

<ParamField body="options.data" type="object">
  User metadata

  <Expandable title="properties">
    <ParamField body="name" type="string">
      Display name for the user
    </ParamField>
  </Expandable>
</ParamField>

### Response

<ResponseField name="access_token" type="string">
  JWT access token
</ResponseField>

<ResponseField name="refresh_token" type="string">
  Refresh token for obtaining new access tokens
</ResponseField>

<ResponseField name="expires_in" type="integer">
  Token expiration time in seconds
</ResponseField>

<ResponseField name="token_type" type="string">
  Token type (bearer)
</ResponseField>

<ResponseField name="user" type="object">
  User object

  <Expandable title="properties">
    <ResponseField name="id" type="string">
      User UUID
    </ResponseField>

    <ResponseField name="email" type="string">
      User email address
    </ResponseField>

    <ResponseField name="user_metadata" type="object">
      Custom user metadata including name
    </ResponseField>
  </Expandable>
</ResponseField>

## Sign In with Password

Authenticate with email and password.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const { data, error } = await supabase.auth.signInWithPassword({
    email: 'user@example.com',
    password: 'securePassword123',
  });
  ```

  ```bash cURL theme={null}
  curl -X POST 'https://your-project.supabase.co/auth/v1/token?grant_type=password' \
    -H 'Content-Type: application/json' \
    -H 'apikey: YOUR_ANON_KEY' \
    -d '{
      "email": "user@example.com",
      "password": "securePassword123"
    }'
  ```
</CodeGroup>

### Request Body

<ParamField body="email" type="string" required>
  User email address
</ParamField>

<ParamField body="password" type="string" required>
  User password
</ParamField>

### Response

<ResponseField name="access_token" type="string">
  JWT access token for API requests
</ResponseField>

<ResponseField name="refresh_token" type="string">
  Token for refreshing the session
</ResponseField>

<ResponseField name="expires_in" type="integer">
  Seconds until token expiration
</ResponseField>

<ResponseField name="user" type="object">
  Authenticated user object with id and email
</ResponseField>

## Sign In with OAuth

Initiate Google OAuth sign-in flow.

```typescript TypeScript theme={null}
const { data, error } = await supabase.auth.signInWithOAuth({
  provider: 'google',
  options: {
    redirectTo: 'https://8space.app/auth/callback'
  }
});

// Redirects to Google OAuth consent screen
// After approval, redirects to callback URL with auth code
```

### Parameters

<ParamField query="provider" type="string" required>
  OAuth provider (`google`)
</ParamField>

<ParamField query="redirect_to" type="string">
  URL to redirect after authentication
</ParamField>

## Get Current User

Retrieve the authenticated user's information.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const { data: { user }, error } = await supabase.auth.getUser();
  ```

  ```bash cURL theme={null}
  curl -X GET 'https://your-project.supabase.co/auth/v1/user' \
    -H 'apikey: YOUR_ANON_KEY' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
  ```
</CodeGroup>

### Response

<ResponseField name="id" type="string">
  User UUID
</ResponseField>

<ResponseField name="email" type="string">
  User email address
</ResponseField>

<ResponseField name="user_metadata" type="object">
  Custom metadata including display name
</ResponseField>

<ResponseField name="app_metadata" type="object">
  System metadata managed by Supabase
</ResponseField>

## Sign Out

End the current user session.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const { error } = await supabase.auth.signOut();
  ```

  ```bash cURL theme={null}
  curl -X POST 'https://your-project.supabase.co/auth/v1/logout' \
    -H 'apikey: YOUR_ANON_KEY' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
  ```
</CodeGroup>

### Response

Returns empty response with status 200 on success.

## Error Handling

All authentication endpoints return errors in this format:

<ResponseField name="message" type="string">
  Human-readable error message
</ResponseField>

<ResponseField name="code" type="string">
  Error code identifier
</ResponseField>

<ResponseField name="details" type="string | null">
  Additional error details
</ResponseField>

<ResponseField name="hint" type="string | null">
  Suggestion for resolving the error
</ResponseField>

## Security

All authenticated endpoints require these headers:

* `apikey`: Supabase anon/service key
* `Authorization`: Bearer token with JWT access token

```typescript Example theme={null}
const headers = {
  'apikey': import.meta.env.VITE_SUPABASE_ANON_KEY,
  'Authorization': `Bearer ${session.access_token}`
};
```
