description |
---|
Moralis is fully integrated with Magic (also known as Magic Link) |
Moralis is fully integrated with Magic which allows you to authenticate your users with their email or other types of social login such as Google or Twitter. __ Learn how the integration works here.
To get started, you will need to make an account here to get a publishable api-key. This key looks like this:
pk_xxxxxxx
{% hint style="danger" %}
Note: Do not use the secret api-key
, that one should never be used on the client-side of your app. This key starts with sk_xxxxxx
{% endhint %}
Import the SDK based on how moralis was imported into the project - CDN, npm, or yarn.
{% tabs %} {% tab title="CDN" %}
<script src="https://auth.magic.link/sdk"></script>
{% endtab %}
{% tab title="npm" %}
npm install magic-sdk
{% endtab %}
{% tab title="yarn" %}
yarn add magic-sdk
{% endtab %} {% endtabs %}
Then call authenticate like above, but with a provider option, and the required params. The email
, apiKey
and network
are all required params.
email
: the email of the user that wants to loginapiKey
the publishable api-key that you can get in your Magic dashboard on http://magic.linknetwork
: one of mainnet, rinkeby, kovan, or ropsten
const user = await Moralis.authenticate({
provider: "magicLink",
email: "[email protected]",
apiKey: "pk_xxxxx",
network: "kovan",
})
When users want to sign up or log in to your application:
- User requests a magic link sent to their email address
- User clicks on that magic link
- User is securely logged into the application
{% hint style="info" %} Magic creates a new crypto address and links it to the user's email when the user enters the email for the first time. {% endhint %}
{% hint style="info" %} Make sure to add your Magic API key in the SignIn.js component. {% endhint %}
{% embed url="https://codesandbox.io/embed/moralis-magic-integration-i5l0b1?fontsize=14&hidenavigation=1&theme=dark" %} Magic Integration with React {% endembed %}
{% embed url="https://youtu.be/gLJ4YejmG2E" %} Moralis and Magic Integration {% endembed %}