wix-login-react-native
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

wix-login-react-native

This is a React Native component that encapsulates Wix's "Managed Login" flow, allowing users to integrate it seamlessly into their app. By using the <WixLogin /> component at the root of your app, you get a login modal that you can open from anywhere in your app, and calls a callback when the user is fully logged in.

For more information about Wix's Managed Login Flow, head over to the Wix Headless documentation.

Installation

Ensure that your React Native project has the following dependencies installed:

  1. react and react-native
  2. @wix/sdk (documentation)
  3. expo-crypto (documentation)
  4. expo-linking (documentation)
  5. react-native-webview (documentation)

Note: These dependencies need to be installed and linked only once in your React Native project.

Then, install this package using the following command:

npm install wix-login-react-native
# or
yarn add wix-login-react-native

Usage

First, add the <WixLogin /> component to the root of your application. Provide the component with two props:

  1. A Wix Client created using createClient(...) and the OAuthStrategy auth option.
  2. A callback function that accepts the user tokens (credentials) once the user is logged in.
import { WixLogin } from 'wix-login-react-native';
import { createClient, OAuthStrategy } from '@wix/sdk';

const client = createClient({ auth: OAuthStrategy({ clientId: '<YOUR_CLIENT_ID>' }) });

const App = () => (
  <WixLogin
    client={client}
    onLoginComplete={tokens => client.auth.setTokens(tokens)}
  />
);

export default App;

Then, from anywhere in your app, import the useWixLogin hook. When you want to prompt the user to login, just run:

import { useWixLogin } from 'wix-login-react-native';

const SomeComponent = () => {
  const wixLogin = useWixLogin();
  
  const handleLogin = () => {
    wixLogin.openLoginModal();
  };

  return (
    <Button title="Login" onPress={handleLogin} />
  );
};

Authorizing your app with Wix

The first time you open the login modal, it may throw an error because you need to configure Wix to trust your app:

In order to make Wix trust your app, go to https://manage.wix.com and choose your Headless project.

From there, go to Settings > Headless Settings: Settings Page

Choose your OAuth App: Headless Settings & OAuth Apps list

And under "Allowed authorization redirect URIs", add the URL provided to you from the error message: Allowed URIs

⚠️ Important: If you’re using Expo Go, the trusted “callback URL” will change once you build your own binary, so make sure to register the production version of your callback URL before you release your app.

Additional Features

Enabling User to Cancel Login

To provide users the option to cancel the login process, you can utilize the allowUserToCancelLogin prop:

<WixLogin
    client={/* ... */}
    onLoginComplete={/* ... */}
    allowUserToCancelLogin
  />

Furthermore, if you need to handle scenarios where the user cancels the login, you can supply a callback function to the onLoginCanceled prop:

<WixLogin
    client={/* ... */}
    onLoginComplete={/* ... */}
    allowUserToCancelLogin
    onLoginCanceled={() => { /* do something */ }}
  />

Package Sidebar

Install

npm i wix-login-react-native

Weekly Downloads

21

Version

1.0.8

License

ISC

Unpacked Size

22.8 kB

Total Files

17

Last publish

Collaborators

  • roysom