Socket
Socket
Sign inDemoInstall

@magic-sdk/react-native-bare

Package Overview
Dependencies
14
Maintainers
27
Versions
449
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @magic-sdk/react-native-bare

Passwordless authentication for React Native (Bare).


Version published
Weekly downloads
1.1K
increased by88.78%
Maintainers
27
Created
Weekly downloads
 

Readme

Source

✨ Magic Authentication JavaScript SDK

<MagicLabs>

Magic empowers developers to protect their users via an innovative, passwordless authentication flow without the UX compromises that burden traditional OAuth implementations.

License · Changelog · Contributing Guide

As of v19.0.0, passcodes (ie. loginWithSMS(), loginWithEmailOTP()) are replacing Magic Links (ie. loginWithMagicLink()) for all of our Mobile SDKs⁠. Learn more

📖 Documentation

See the developer documentation to learn how you can master the Magic SDK in a matter of minutes.

🔗 Installation

Integrating your app with Magic will require our client-side NPM package:

# Via NPM:
npm install --save @magic-sdk/react-native-bare
npm install --save react-native-device-info # Required Peer Dependency
npm install --save @react-native-community/async-storage # Required Peer Dependency
npm install --save react-native-safe-area-context # Required Peer Dependency
npm install --save @react-native-community/netinfo # Required Peer Dependency

# Via Yarn:
yarn add @magic-sdk/react-native-bare
yarn add react-native-device-info # Required Peer Dependency
yarn add @react-native-community/async-storage # Required Peer Dependency
yarn add react-native-safe-area-context # Required Peer Dependency
yarn add @react-native-community/netinfo # Required Peer Dependency

⚡️ Quick Start

Sign up or log in to the developer dashboard to receive API keys that will allow your application to interact with Magic's authentication APIs.

Then, you can start authenticating users with just one method!

import React from 'react';
import { Magic } from '@magic-sdk/react-native-bare';
import { SafeAreaProvider } from 'react-native-safe-area-context';

const magic = new Magic('YOUR_API_KEY');

export default function App() {
  return <>
	 <SafeAreaProvider>
	    {/* Render the Magic iframe! */}
	    <magic.Relayer />
	    {...}
	 </SafeAreaProvider>
  </>
}

// Somewhere else in your code...
await magic.auth.loginWithEmailOTP({ email: 'your.email@example.com' });

⁠⁠👉 Check out some of our React Native Demo apps for inspiration! 👀

👀 SafeAreaView

Please note that as of v14.0.0 our React Native package offerings wrap the <magic.Relayer /> in react-native-safe-area-context's <SafeAreaView />. To prevent any adverse behavior in your app, please place the Magic iFrame React component at the root view of your application wrapped in a SafeAreaProvider as described in the documentation.

We have also added an optional backgroundColor prop to the Relayer to fix issues with SafeAreaView showing the background. By default, the background will be white. If you have changed the background color as part of your custom branding setup, make sure to pass your custom background color to magic.Relayer:

<magic.Relayer backgroundColor="#0000FF"/>

🙌🏾 Troubleshooting

Symlinking in Monorepo w/ Metro

For React Native projects living within a monorepo that run into the following TypeError: Undefined is not an object error:

Screenshot 2022-11-23 at 12 19 19 PM

When attempting to import Magic, take note that the React Native metro bundler doesn’t work well with symlinks, which tend to be utilized by most package managers.

For this issue consider using Microsoft's rnx-kit suite of tools that include a plugin for metro that fixes this symlink related error.

Handling internet connection problems

When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with a MagicSDKError:

{
  "code": "MODAL_NOT_READY",
  "rawMessage": "Modal is not ready."
}

It is good practice to use @react-native-community/netinfo to track the internet connection state of the device. For your convenience, we've also added a hook that uses this library behind the scenes:

import { useInternetConnection } from '@magic-sdk/react-native-expo';

const magic = new Magic('YOUR_API_KEY');

const connected = useInternetConnection()

useEffect(() => {
   if (!connected) {
       // Unomount this component and show your "You're offline" screen.
   }
}, [connected])

export default function App() {
   return <>
       <SafeAreaProvider>
           {/* Render the Magic iframe! */}
           <magic.Relayer />
           {...}
       </SafeAreaProvider>
   </>
}

FAQs

Last updated on 01 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc