Overview
Authenticate a user passwordlessly using a “magic link” sent to the specified user’s email address.Compatibility
Magic link SDK methods are available via the Web client-side SDK. These methods are deprecated on all mobile SDKs.Usage
TheloginWithMagicLink
function sends an authentication request to the user. The resolved value is a Decentralized ID token with a default 15-minute lifespan. **Refer to the **API documentation for information on how to install and initialize Magic.
JavaScript
Error Handling
To achieve a fully white-labeled experience, you will need to implement some custom error handling according to your UI needs. Here’s a short example to illustrate how errors can be caught and identified by their code:JavaScript
Test Mode
Magic’s client-side Web SDK provides Test Mode as a quick way to test your integration locally by asserting specific error codes or bypassing the magic link flow completely. Test Mode only works when logging in with Magic links. As the name suggests, this is for testing. Users and wallets created in test mode should not be treated as secure or production-ready. Data surfaced while in Test Mode should not be considered secure, accurate, or production-ready. To enable Test Mode, providetestMode: true
to the SDK constructor.
JavaScript
loginWithMagicLink
:
- To assert a success state, use
[email protected]
- To assert a failed state, use
[email protected]
- To assert a case-specific failed state, provide an RPC error code with
test+fail_with_{RPC_ERROR_CODE}@magic.link
test+success_with_{PUBLIC_KEY:PRIVATE_KEY}@magic.link
.
The key-pair provided in the email address during test mode is not protected
by Magic’s delegated key management system. These keys should not be
considered secure or private. Never store mainnet funds with these keys!
JavaScript
Security Notes
IP Address Verification
Magic’s top priority is ensuring secure authentication for your end users in your app. Magic recently implemented and added a layer of security for all login flows with email magic link. Specifically, the change ensures that the IP address associated with the device that a user enters their email address on matches the IP address associated with the device that clicks the magic link. If the IP address does not match, the following error is shown to the user when they click on the magic link.