For the complete documentation index, see llms.txt. This page is also available as Markdown.
Context
MoonContextProvider Documentation
The MoonContextProvider is a React context provider that provides access to the Moon SDK and Ethers.js provider instances, as well as various authentication and session management functions. This documentation page will guide you through the basics of using the MoonContextProvider in your React Native project.
Table of Contents
Installation
Usage
Context Values
Example
Installation
To use the MoonContextProvider in your project, you'll need to install the @moonup/moon-react-native package. You can install it using npm:
npminstall@moonup/moon-react-native
Usage
To use the MoonContextProvider, you'll need to wrap your application with it. Here's an example of how to do this:
Signs in a user with the provided email and password.
Example:
signOut()
Signs out the current user.
Example:
signInWithDiscord()
Signs in a user using Discord OAuth.
Example:
signInWithGithub()
Signs in a user using GitHub OAuth.
Example:
signInWithTwitter()
Signs in a user using Twitter OAuth.
Example:
signInWithGoogle()
Signs in a user using Google OAuth.
Example:
sendMagicLink(email: string)
Sends a magic link to the provided email address.
Example:
Context Provider Variables
user
The current user object, or null if the user is not authenticated.
Example:
session
The current session object, or null if the user is not authenticated.
Example:
initialized
A boolean value indicating whether the authentication state has been initialized.
Example:
moon
An instance of the Moon SDK.
Example:
ethers
An instance of the Ethers.js provider.
Example:
Example
Here's an example of how to use the MoonContextProvider to sign in a user with Discord OAuth:
In this example, we import the useMoon hook from the @moonup/moon-react-native package and use it to access all of the context provider functions and variables. We then use these functions and variables to handle various authentication and session management tasks, such as signing up a new user, signing in a user with a password, signing out a user, connecting to the Moon API, disconnecting from the Moon API, getting the current user session, connecting to the Ethers.js provider, disconnecting from the Ethers.js provider, sending a request to the Ethers.js provider, and sending a magic link to a user's email address.
In this example, we import the useMoon hook from the @moonup/moon-react-native package and use it to access the signInWithDiscord function. We then use this function to sign in a user with Discord OAuth when the button is pressed.