> ## Documentation Index
> Fetch the complete documentation index at: https://corebase-docs-new.trivyaa.in/llms.txt
> Use this file to discover all available pages before exploring further.

# User Accounts

> Manage users securely with simple commands.

CoreBase makes it easy to handle user accounts. You can sign users up, log them in, and manage their sessions without complex code.

<Note>
  CoreBase handles sessions automatically, so users stay logged in even if they refresh the page.
</Note>

## Sign Up

Create a new account for a user.

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

if (error) {
  console.error('Signup failed:', error);
} else {
  console.log('Welcome!', data.user);
}
```

## Sign In

Log in an existing user.

```typescript theme={null}
const { data, error } = await corebase.auth.signIn({
  email: 'user@example.com',
  password: 'securePassword123'
});

if (error) {
  console.error('Login failed:', error);
} else {
  console.log('Logged in successfully:', data.user);
}
```

## Get Current User

Check who is currently logged in.

```typescript theme={null}
const { data, error } = await corebase.auth.getUser();

if (data) {
  console.log('Current user:', data.user);
}
```

## Sign Out

Log out the current user securely.

```typescript theme={null}
await corebase.auth.signOut();
```

## Sign In with a Provider (OAuth)

CoreBase also supports Google and GitHub sign-in. Unlike the methods above, this is a
redirect flow, not a promise you await directly — the gateway completes the exchange
with the provider and sends the user back to your app.

<Steps>
  <Step title="Redirect to the provider">
    Send the browser to the OAuth URL, passing your project's ID.

    ```typescript theme={null}
    window.location.href = corebase.auth.getOAuthUrl('google', projectId);
    // or 'github'
    ```
  </Step>

  <Step title="Read the tokens on your success page">
    CoreBase redirects back to your configured success URL with the session in the query string.

    ```typescript theme={null}
    const params = new URLSearchParams(window.location.search);

    corebase.auth.setSessionFromTokens({
      access_token: params.get('access_token')!,
      refresh_token: params.get('refresh_token') ?? undefined,
      user: { id: params.get('user_id')!, email: '' },
    });
    ```
  </Step>
</Steps>

<Note>
  Configure your Google/GitHub client ID and secret for the project first, via
  `corebase.auth.updateAuthConfig(projectId, { google_client_id, google_client_secret })`.
</Note>

## Refreshing a Session

Sessions refresh automatically in most cases. If you need to do it manually:

```typescript theme={null}
const { data, error } = await corebase.auth.refreshSession();
```
