open-index/open-npm huggingface dataset:
npm package: @moonpay/auth-sdk
Description: The MoonPay Authentication SDK
Author: MoonPay, Inc.
Latest version: 0.1.48

# MoonPay Authenticate SDK

The MoonPay Authenticate SDK is a library that provides a simple way to handle user authentication for MoonPay services. It allows you to easily integrate MoonPay's authentication flow into your application, providing a seamless experience for your users.

## Getting Started

### 1. Install the dependencies

To install the dependencies, run the following command in the root directory:

```shell
npm install
```

### 2. Run the Authenticate SDK

Run the command in the packages/auth-sdk directory:

To run the project in dev mode:

```shell
npm run dev
```

To build the project:

```shell
npm run build
```

### 3. Connect to the MoonPay Authenticate SDK

To connect to the MoonPay Auth SDK, you can either connect to local environment, or to production environment on auth.moonpay.com. You can use the test publishable key for testing purposes.

#### For local environment

1. In this repo, run the Authenticate package:

```
npm run auth:dev
```

2. In Moonpay-api run the public api:

```shell
npm run dev:public-api
```

3. Configure the SDK:

```typescript
const sdk = new MoonPayAuthSDK('pk_test_123', {
  devApiUrl: 'http://localhost:4000',
  devAuthDomain: 'http://localhost:5001',
});
```

#### For production environment

Just set the SDK configuration to the remote URL:

```typescript
const sdk = new MoonPayAuthSDK({
  apiKey: 'pk_test_123',
  devDomain: 'https://auth.moonpay.com',
  authType: 'EMAIL_OTP',
});
```

### 4. Implement Login and Logout

You can now use the SDK methods to manage user authentication. Here's a simple example of how to handle login and logout:

```typescript
import { useState, useEffect } from 'react';

// State to track user login status
const [isLoggedIn, setIsLoggedIn] = useState(false);

// Initialize the SDK
useEffect(() => {
  const loadSdk = async () => {
    await sdk.init();
  };

  loadSdk();
}, []);

// Handle user login
const handleLogin = async () => {
  if (sdk) {
    sdk.showUI();

    let authResult = await sdk.login();
    // Handle the authentication result
    if (authResult.success) {
      setIsLoggedIn(true);
    } else {
      setIsLoggedIn(false);
    }
  }
};

// Handle user logout
const handleLogout = async () => {
  if (sdk) {
    let logoutResult = await sdk.logout();
    // Handle the logout result
    if (logoutResult.success) {
      setIsLoggedIn(false);
    }
  }
};
```

See the extensive docs and examples [here](<[url](https://moonpay.readme.io/docs/auth-sdk)https://moonpay.readme.io/docs/auth-sdk>).