0.1.48 • Published 1 year ago

@moonpay/auth-sdk v0.1.48

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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:

npm install

2. Run the Authenticate SDK

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

To run the project in dev mode:

npm run dev

To build the project:

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
  1. In Moonpay-api run the public api:
npm run dev:public-api
  1. Configure the SDK:
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:

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:

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.

0.1.46

1 year ago

0.1.47

1 year ago

0.1.48

1 year ago

0.1.45

1 year ago

0.1.44

1 year ago

0.1.43

1 year ago

0.1.42

1 year ago

0.1.41

1 year ago

0.1.40

1 year ago

0.1.39

1 year ago

0.1.38

1 year ago

0.1.37

1 year ago

0.1.36

1 year ago

0.1.34

1 year ago

0.1.35

1 year ago

0.1.33

1 year ago

0.1.32

1 year ago

0.1.31

1 year ago

0.1.30

1 year ago

0.1.29

1 year ago

0.1.28

1 year ago

0.1.27

1 year ago

0.1.26

1 year ago

0.1.25

1 year ago

0.1.24

2 years ago

0.1.22

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago